Lennart Fridén
codecoupled.org | @DevLCSC | github.com/DevL
Stockholm Google Developer Group March 2016 Meetup
defmodule Hello do
def world do
IO.puts "Hello GDG!"
end
end
-module(hello).
-export([world/0]).
world() ->
io:fwrite("Hello, GDG\n").
defmodule Hello do
def world do
IO.puts "Hello GDG!"
end
end
class Hello
def world
puts "Hello GDG!"
end
end
defmodule Request do
def make_it do
handle(some_function_that_can_return_different_things)
end
defp handle({:ok, result}), do: result
defp handle({:error, message}), do: Logger.error(message)
defp handle(_), do: Logger.error("An unexpected thing happened")
end
defmacro divisible_by?(number, divisor) do
quote do
rem(unquote(number), unquote(divisor)) == 0
end
end
def double_everything_except_fivers(a_bunch_of_numbers)
Enum.map(
Enum.reject(a_bunch_of_numbers,
fn(element) -> divisible_by?(element, 5) end),
fn(element) -> element * 2 end)
end
def double_everything_except_fivers(a_bunch_of_numbers) do
a_bunch_of_numbers
|> Enum.reject(fn(number) -> divisible_by?(number, 5) end)
|> Enum.map(fn(number) -> number * 2 end)
end
def double_everything_except_fivers(a_bunch_of_numbers) do
a_bunch_of_numbers
|> Enum.reject(&divisible_by_five?(&1))
|> Enum.map(&double(&1))
end
defp divisible_by_five?(value), do: divisible_by?(value, 5)
defp double(value), do: value * 2
@doc """
Returns a `Stream` of datetimes, starting with `datetime`, stepping backward one second at a time.
## Examples
iex> {{2015, 2, 27}, {18, 30, 45}} |> all_seconds_before |> Enum.take(3)
[{{2015, 2, 27}, {18, 30, 45}},
{{2015, 2, 27}, {18, 30, 44}},
{{2015, 2, 27}, {18, 30, 43}}]
"""
@spec all_seconds_before(GoodTimes.datetime) :: Enumerable.t
def all_seconds_before(datetime) do
datetime |> Stream.iterate(&GoodTimes.a_second_before/1)
end
Interactive Elixir (1.2.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> h GoodTimes.Generate.all_seconds_before
def all_seconds_before(datetime)
Returns a Stream of datetimes, starting with datetime, stepping backward one
second at a time.
Examples
┃ iex> {{2015, 2, 27}, {18, 30, 45}} |> all_seconds_before |> Enum.take(3)
┃ [{{2015, 2, 27}, {18, 30, 45}},
┃ {{2015, 2, 27}, {18, 30, 44}},
┃ {{2015, 2, 27}, {18, 30, 43}}]
Lennart Fridén
codecoupled.org | @DevLCSC | github.com/DevL
Stockholm Google Developer Group March 2016 Meetup