-
Notifications
You must be signed in to change notification settings - Fork 600
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
Add Streams #182
Add Streams #182
Conversation
a30ef2f
to
25b1d7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I love seeing the koans grow and improve. I left a few comments that you will hopefully find useful.
❤️
@intro "Streams" | ||
|
||
koan "Streams are lazier than Enum, they only return a struct" do | ||
assert Stream.map([1, 2, 3], &(&1 + 1)).__struct__ == ___ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a learner, I wouldn't know what the form of the structure is here. It might also be nice to explain why a structure is returned. Something like "Unlike Enum, a Stream does not execute immediately. It instead returns a struct the represents the enumeration to be performed later". I'm not a huge fan of that wording, but does is my point clear?
It might also be nice to initially have an example like "Streams iterate over collections and Enums" followed by something like "But they're lazy".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I wonder how I can demonstrate laziness? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felipesere Throw some IO in the mapping function?
lib/koans/19_streams.ex
Outdated
assert Stream.map([1, 2, 3], &(&1 + 1)).__struct__ == ___ | ||
end | ||
|
||
koan "You have to ask it explicitly to do the operation" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the term often used for these operations are "terminal operations". So you might word this like "Streams are executed by terminal operations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/koans/19_streams.ex
Outdated
koan "You have to ask it explicitly to do the operation" do | ||
updated_list = | ||
[1, 2, 3] | ||
|> Stream.map(&(&1 + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're missing something important in these examples, an illustration that streams avoid iterating over a collection multiple times. That might be hard to illustrate, do you have any ideas? At the very least, we should probably have an example that shows piping multiple Stream calls together to make the point that each one does not represent an iteration through the collection, but rather a "stacking" of the streamed behavior in the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way I can think of this is to play with side effects by having the individual 'transformations' that get stacked send a value to a pid and then inspecting the order in which they were received?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this example was more to show how to execute an operation on a Stream. In this very case, even if the use of a Stream isn't ideal it's still a possibility.
That's why I preferred to create another example that demonstrates that you can compute a selected part of the Stream.
This pull request add some basic koan about stream reading
[Closes #12]