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

Add Streams #182

Closed
wants to merge 2 commits into from
Closed

Conversation

fabientownsend
Copy link
Contributor

@fabientownsend fabientownsend commented Mar 30, 2017

This pull request add some basic koan about stream reading

[Closes #12]

Copy link
Collaborator

@iamvery iamvery left a 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__ == ___
Copy link
Collaborator

@iamvery iamvery Apr 3, 2017

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".

Copy link
Collaborator

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? 🤔

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?

assert Stream.map([1, 2, 3], &(&1 + 1)).__struct__ == ___
end

koan "You have to ask it explicitly to do the operation" do
Copy link
Collaborator

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

koan "You have to ask it explicitly to do the operation" do
updated_list =
[1, 2, 3]
|> Stream.map(&(&1 + 1))
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@felipesere felipesere closed this Mar 28, 2018
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.

4 participants