7
\$\begingroup\$

I recently got started with Elixir. I'm used to F#'s pipes, and Seq.map and LINQ's .Select statements. Things are different in Elixir, and the code I have seems very ugly. Anon functions in anon functions.

defrecord FileData, name: "", date: nil
 def filedetails() do
 files = File.ls!
 datestr = fn {{year, month, day}, _time} -> "#{day}/#{month}/#{year}" end
 filedates = files |> (Stream.map &(File.stat!(&1)))
 |> (Stream.map &(&1.ctime))
 |> Stream.map &(datestr.(&1))
 Enum.zip(files,filedates)
 |> Enum.map fn {n,d}->FileData[name: n, date: d] end
 end

How should this be done?

Mathieu Guindon
75.5k18 gold badges194 silver badges467 bronze badges
asked Jan 18, 2014 at 3:56
\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

I'm not sure why you'd need to pipe three different streams - one for every manipulation. I'd probably use one Stream to do all the manipulations together, something like:

filedates = files |> Stream.map &((&1 |> File.stat!).ctime |> datastr.())

or

filedates = files |> Stream.map &(File.stat!(&1).ctime |> datastr.())
answered Aug 14, 2014 at 12:17
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.