items = map|> Enum.sort_by(&elem(&1, 1))|> Enum.map(&elem(&1, 0))
items = map|> Enum.sort_by (elem 1)|> Enum.map (elem 0)
&some_fun(a, b, ...) == &some_fun(&1, a, b, ...)
items = map|> Enum.sort_by( &elem(1) )|> Enum.map( &elem(0) )
words_with_a =filename|> File.stream!|> Stream.flat_map(&String.split(" "))|> Stream.filter(&String.contains("a"))
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/0a3f2be5-8ab7-43f5-92ac-bda9fb535022%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
words_with_a =filename|> File.stream!|> Stream.flat_map(&> String.split(" "))|> Stream.filter(&> String.contains("a"))
get_words_with_a =&> File.stream!&> Stream.flat_map(&> String.split(" "))&> Stream.filter(&> String.contains("a"))
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/de1e92a6-a0df-4f1e-aefe-dac877a91901%40googlegroups.com.
words_with_a =filename|> File.stream!|> Stream.flat_map(&> String.split(" "))|> Stream.filter(&> String.contains("a"))
words_with_a =filename|> File.stream!|> Stream.flat_map(&String.split(&1, " "))|> Stream.filter(&String.contains(&1, "a"))
I just wrote this code
items = map
|> Enum.sort_by(&elem(&1, 1))
|> Enum.map(&elem(&1, 0))
and though if I should rewrite is as a lambda because maybe I wouldn't understand it in the future.
items =map|> Enum.sort_by(fn {_, bar} -> bar end)|> Enum.map(fn {foo, _} -> foo end)
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/0a3f2be5-8ab7-43f5-92ac-bda9fb535022%40googlegroups.com.
I just wrote this code
items = map
|> Enum.sort_by(&elem(&1, 1))
|> Enum.map(&elem(&1, 0))
and though if I should rewrite is as a lambda because maybe I wouldn't understand it in the future.
Just a suggestion: it would have been more readable if you wrote it asitems =map|> Enum.sort_by(fn {_, bar} -> bar end)|> Enum.map(fn {foo, _} -> foo end)Of course, assuming that you replace the placeholders "foo" and "bar" with the names that describe what your tuple elements are. It is more verbose but objectively more descriptive: first, sort it by "bars" and then return just the "foos".
But your suggestion is not equivalent to the OP's: it only works if the input list is made of tuples of exactly size 2 (instead of "at least" size 2).
items =map|> Enum.sort_by(fn{_, bar} -> bar
{_, bar, _} -> bar
end)|> Enum.map(fn{foo, _} -> foo
{foo, _, _} -> fooend)
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/356d6d74-6a2b-4014-bf9c-db2ba460350e%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAAPY6eOQc1gJ%3DL1QqJWB_r-Rvk-JpkHBWBAxT%3DN3DE3Q5FB05A%40mail.gmail.com.