I’m reading this nice book series, Phoenix inside out. At one point database is seeded from a CSV file.
Following is the code at page 131-132 (seeds.exs)
From this code I for the first time learnt that functions passed to the Enum.each can have multiple steps separated by new lines.
After -> there are actually 4 steps starting from is_seasonal, price, %Product{ and |> Repo respectively.
My questions are,
Can these steps be separated by something other than just a new line, like some comma or something else, because (coming from imperative languages) that will look more readable.
Can I move |> Repo.insert() below the end) in the last line?
Can these steps be separated by something other than just a new line, like some comma or something else, because (coming from imperative languages) that will look more readable.
Now after your answer I think that moving it outside and making it insert_all may make it more efficient like converting N+1 database query into a multiple query.