This file contains hidden or 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
| (ns countries.core | |
| (:gen-class)) | |
| (def countries { | |
| :AF "Afghanistan", | |
| :AX "Åland Islands", | |
| :AL "Albania", | |
| :DZ "Algeria", | |
| :AS "American Samoa", | |
| :AD "Andorra", |
This file contains hidden or 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 Catstore do | |
| def start() do | |
| {:ok, store} = Agent.start(fn -> ["Biggles"] end) | |
| store | |
| end | |
| def pr_cats(cats) do | |
| Enum.each(cats, fn cat -> IO.puts cat end) | |
| end |
This file contains hidden or 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 Catstore do | |
| def start() do | |
| {:ok, store} = Agent.start(fn -> ["Biggles"] end) | |
| store | |
| end | |
| def pr_cats(cats) do | |
| Enum.each(cats, fn cat -> IO.puts cat end) | |
| end |
This file contains hidden or 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 LlCatStore do | |
| def loop(cats) do | |
| receive do | |
| {:add, cat} -> | |
| IO.puts "adding cat #{cat}" | |
| loop([cat | cats]) | |
| {:remove, cat} -> | |
| IO.puts "removing cat #{cat}" | |
| loop(remove_cat(cat, cats)) |
This file contains hidden or 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 Foo do | |
| def sleep(num) do | |
| :timer.sleep(num) | |
| self() | |
| end | |
| end | |
| t = Task.async(fn -> Foo.sleep(15000) end) | |
| IO.inspect Task.await(t, 20000) |
This file contains hidden or 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 Fr do | |
| def read_file(f) do | |
| File.read!(f) | |
| end | |
| def to_s(num) do | |
| Integer.to_string(num) | |
| end |
This file contains hidden or 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
| Enum.reduce(Enum.map([1,2,3,4], fn(x) -> x*2 end), 0, fn(x,acc) -> x + acc end) |
This file contains hidden or 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
| def greeter() do | |
| fn | |
| :droid -> IO.puts "Yikes, a droid" | |
| "Han Solo" -> :pilot | |
| %{:name => name, :droid => true} -> name <> "-NG" | |
| {droid, human, stormtrooper} -> IO.puts "#{droid}'s rule!" | |
| any -> :ok | |
| end | |
| end | |
This file contains hidden or 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
| sum = &(&1 + &2 + &3 + &4) | |
| sum.(4,4,4,4) |
This file contains hidden or 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 Modfuncs do | |
| def modelx(%{:name => name, :droid => true}) do | |
| name <> "-NG" | |
| end | |
| def modelx(%{:name => name, :droid => false}) do | |
| name | |
| end | |
| end |
NewerOlder