Skip to content

Instantly share code, notes, and snippets.

@edmz
Last active May 1, 2016 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edmz/e850f0e1b66614487177 to your computer and use it in GitHub Desktop.
Save edmz/e850f0e1b66614487177 to your computer and use it in GitHub Desktop.
Elixir version of[1] as revised by José Valim 1. http://devblog.avdi.org/2013/10/16/sorting-lines-in-5-languages/
# this version is by José Valim, my version was way more verbose and not quite as elixir-ish.
[input, output] = System.argv
File.write!(output, File.stream!(input) |> Enum.sort |> Enum.join(""))
@avdi
Copy link

avdi commented Oct 16, 2013

I'm curious if we could get the File.write into the pipeline as well somehow...

@edmz
Copy link
Author

edmz commented Oct 16, 2013

If i'm not mistaken, the reason for that is that when using pipelines, the resulting value of one method is what gets sent as the first paramater of the next call. File.write!() needs the path as the first parameter.

@avdi
Copy link

avdi commented Oct 16, 2013

I'm pretty sure that could be taken care of using & notation.

@alco
Copy link

alco commented May 1, 2016

The |> Enum.join("") part is unnecessary.

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