re: Alright, Break It Up! Using Partition/ Chunk VIEW POST

VIEW FULL DISCUSSION

You probably want to have closing ends for funs in your last example, or even use “the most sexiest part of the language,” according to José:

def is_speeding_one_minute_plus(data)
  data
  |> Enum.drop_while(& &1[speed] <= &1[speed_limit])
  |> Enum.chunk_by(& &1[speed] > &1[speed_limit])
  |> Enum.take_every(2)
  |> Enum.map(fun x ->
    head = hd(x)
    %{start: head,
      duration: DateTime.diff(List.last(x)[timestamp] - head[timestamp])}
  end)
  |> Enum.filter(& &1[duration] >= 60)
end

Pentalinguistics is hard :)

P.S. Great explanation, thank you.

Ahh, you're right! That's what I get for hastily typing it up. Thanks for the catch!

code of conduct - report abuse