Skip to content

Instantly share code, notes, and snippets.

@archie
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archie/1095f1ba3792f5361122 to your computer and use it in GitHub Desktop.
Save archie/1095f1ba3792f5361122 to your computer and use it in GitHub Desktop.
Playing with pipes in Elixir
defmodule Upptec do
def study(topics, match) do
Stream.filter(topics, fn topic -> Regex.match?(match, topic) end)
end
def consider(topics, time_available) do
Stream.map(topics, fn topic ->
duration = :random.uniform(time_available)
{topic, duration}
end)
end
def teach(topics, colleage, student) do
Stream.each(topics, fn ({topic, duration}) ->
IO.puts("#{colleage} taught #{student} #{topic} in #{duration} time.")
end)
end
def lets_do_it do
topics = ["elixir pipes", "driving a car", "OTP in elixir", "what a computer is"]
Upptec.study(topics, ~r/elixir/) |> Upptec.consider(1000) |> Upptec.teach(:marcus, :morgan) |> Enum.to_list
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment