Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 'stream', add a few examples #705

Merged
merged 10 commits into from
Nov 25, 2024
Merged

Refactor 'stream', add a few examples #705

merged 10 commits into from
Nov 25, 2024

Conversation

jiribenes
Copy link
Contributor

@jiribenes jiribenes commented Nov 22, 2024

Update: 'stream' got slightly refactored (using Any everywhere now), fixed a few bugs, added a few examples of push streams, pull streams, their infinite variants, limit, zip, ...


I added a few examples for the new stream stdlib into examples/stdlib.
I'd also be happy to add some Nice ®️ example into the stream.effekt file itself (either into the doc comments or as a namespace examples { ... } thing)

I couldn't figure out how to use take properly in a sane (nice idiomatic) way, since it requires me to handle stop and I couldn't find any nicely looking way to do that. Therefore all of these examples are just simple, finite push streams. EDIT: solved

I also tried adding zip in order to iterate through multiple streams in step, but I'm not sure how idiomatic it is (see comments below).

@phischu, please let me know if I'm using the stream library as you envisioned it.
If not, feel free to go ahead and change the examples so that they are closer to what you'd want. :)

TODO (in an ideal world)

  • at least one simple example with pull streams
  • one example using both pull streams and push streams
  • some example with infinite streams
  • make zip nicer to use?

@jiribenes jiribenes requested a review from phischu November 22, 2024 15:44
@jiribenes
Copy link
Contributor Author

jiribenes commented Nov 23, 2024

Also, I just tried using a "for-each" on characters, but it doesn't act the way I'd expect as per the pun:

import stream

def main() = {
  for[Char] { each("Hello") } { c =>
    println(show(c) ++ " (" ++ show(c.toInt) ++ ")")
  }
}

as it prints an infinite stream of:

H (72)
H (72)
H (72)
H (72)
H (72)
H (72)
H (72)
H (72)
H (72)
H (72)
...

Similarly the code hangs in an infinite loop when I do:

def main() = {
  val list = collectList[Char] { each("Hello") }
  println(list.map { (c: Char) => show(c) })
}

which I'd presume would just output ['H', 'e', 'l', 'l', 'o'].

Copy link
Contributor Author

@jiribenes jiribenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (modulo small whitespace changes)

examples/benchmarks/input_output/word_count_ascii.effekt Outdated Show resolved Hide resolved
examples/benchmarks/input_output/word_count_utf8.effekt Outdated Show resolved Hide resolved
@jiribenes jiribenes changed the title Add a few examples for 'stream' Refactor 'stream', add a few examples Nov 25, 2024
@jiribenes jiribenes merged commit b034213 into master Nov 25, 2024
2 checks passed
@jiribenes jiribenes deleted the examples/stream branch November 25, 2024 14:15
b-studios pushed a commit that referenced this pull request Dec 24, 2024
'stream' got slightly refactored (using `Any` everywhere now),
fixed a few bugs, added a few examples of push streams, pull streams,
their infinite variants, `limit`, `zip`, ...

---------

Co-authored-by: Philipp Schuster <[email protected]>
EveEme pushed a commit to EveEme/effekt that referenced this pull request Jan 20, 2025
'stream' got slightly refactored (using `Any` everywhere now),
fixed a few bugs, added a few examples of push streams, pull streams,
their infinite variants, `limit`, `zip`, ...

---------

Co-authored-by: Philipp Schuster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants