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

Possible mistake in the Getting Started example for "Enumerables & Streams/Eager vs Lazy" #4826

Closed
akitaonrails opened this issue Jun 18, 2016 · 3 comments

Comments

@akitaonrails
Copy link

akitaonrails commented Jun 18, 2016

I was trying this example from this section in the Getting Started guide:

1..100_000 |> Stream.map(&(&1 * 3)) |> Stream.filter(odd?)

It blows the following error:

** (CompileError) iex:18: undefined function odd?/0
    (elixir) expanding macro: Kernel.|>/2
             iex:18: (file)

I think the correct example would be using the Integer.is_odd macro, wouldn't it?

require Integer
1..100_000
  |> Stream.map(&(&1 * 3))
  |> Stream.filter(&(Integer.is_odd(&1)))
  |> Enum.sum
@josevalim
Copy link
Member

Hi @akitaonrails! :D We did define the odd? function in the previous section: http://elixir-lang.org/getting-started/enumerables-and-streams.html#eager-vs-lazy

Maybe we should make it clearer?

@josevalim
Copy link
Member

@akitaonrails I am closing this but please let me know if you think we can make it clearer. Thank you! :D

@akitaonrails
Copy link
Author

Ah, sorry, you're right :-) I was copying this snippet to use in a presentation (I say it's from the getting started in the site), so without context it fails, but following step by step it does work. Not a bug, just out of context from my part indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants