Last active
August 29, 2015 14:01
-
-
Save archie/1095f1ba3792f5361122 to your computer and use it in GitHub Desktop.
Playing with pipes in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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