: ~/fs/Courses/cps506/f2017/Notes/October05 ; iex Eshell V8.2 (abort with ^G) Interactive Elixir (1.4.1) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> parent = self() #PID<0.81.0> iex(2)> spawn(fn()-> send(parent,42) end) #PID<0.84.0> iex(3)> receive do x -> x end 42 iex(4)> receive do x -> x end ^C ^C BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution : ~/fs/Courses/cps506/f2017/Notes/October05 ; iex Eshell V8.2 (abort with ^G) Interactive Elixir (1.4.1) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> parent = self() #PID<0.81.0> iex(2)> spawn(fn()-> receive do x -> send(parent,x+25) end end) #PID<0.84.0> iex(3)> receive do after 10 -> 0 end 0 iex(4)> receive do after 5000 -> 0 end 0 iex(5)> child = spawn(fn()-> receive do x -> send(parent,x+25) end end) #PID<0.90.0> iex(6)> send(child,17) 17 iex(7)> receive do x -> x end 42 iex(8)> send(child,17) 17 iex(9)> child = spawn(fn()-> receive do {pid,x} -> send(pid,x+25) end end) #PID<0.96.0> iex(10)> send(child,{self(),17}) {#PID<0.81.0>, 17} iex(11)> receive do x -> x end 42 iex(12)> kwl = [hello: true, other: 42] [hello: true, other: 42] iex(13)> kwl[:hello] true iex(14)> kwl[:other] 42 iex(15)> kwl2 = Keyword.merge([hello: false, other: 0, something: 17], kwl) [something: 17, hello: true, other: 42] iex(16)> map = %{hello: true,other:42} ** (SyntaxError) iex:16: keyword argument must be followed by space after: other: iex(16)> map = %{hello: true,other: 42} %{hello: true, other: 42} iex(17)> map[:hello] true iex(18)> map2 = map |> Map.add(:abc,5) ** (UndefinedFunctionError) function Map.add/3 is undefined or private (elixir) Map.add(%{hello: true, other: 42}, :abc, 5) iex(18)> map2 = map |> Map.put(:abc,5) %{abc: 5, hello: true, other: 42} iex(19)> map2 = map |> Map.put(:abc,5) |> Map.put(:other, 88) %{abc: 5, hello: true, other: 88} iex(20)> map %{hello: true, other: 42} iex(21)> map2 = map |> Map.put(:abc,5) |> Map.put(46, 88) %{46 => 88, :abc => 5, :hello => true, :other => 42} iex(22)> 1..3 |> Enum.map(&IO.inspect(&1)) 1 2 3 [1, 2, 3] iex(23)> 1..3 |> Enum.map(&IO.inspect(&1)) |> Enum.map(&(&1+&1)) 1 2 3 [2, 4, 6] iex(24)> 1..3 |> Enum.map(&IO.inspect(&1)) |> Enum.map(&(&1+&1)) |> Enum.map(&IO.inspect(&1)) 1 2 3 2 4 6 [2, 4, 6] iex(25)> 1..3 |> Stream.map(&IO.inspect(&1)) |> Stream.map(&(&1+&1)) |> Stream.map(&IO.inspect(&1)) #Stream<[enum: 1..3, funs: [#Function<47.36862645/1 in Stream.map/2>, #Function<47.36862645/1 in Stream.map/2>, #Function<47.36862645/1 in Stream.map/2>]]> iex(26)> 1..3 |> Stream.map(&IO.inspect(&1)) |> Stream.map(&(&1+&1)) |> Stream.map(&IO.inspect(&1)) |>Enum.to_list() 1 2 2 4 3 6 [2, 4, 6] iex(27)> 1.. |>Stream.take(5) ** (SyntaxError) iex:27: syntax error before: '|>' iex(27)> Stream.cycle(1..5) |>Stream.take(12) #Stream<[enum: #Function<9.36862645/2 in Stream.cycle/1>, funs: [#Function<55.36862645/1 in Stream.take/2>]]> iex(28)> Stream.cycle(1..5) |>Stream.take(12) |> Enum.to_list() [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2] iex(29)> Stream.cycle(1..5) |>Stream.take(120) |> Enum.to_list() [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...] iex(30)> Stream.concat(Stream.cycle(1..5)|>Stream.take(12),Stream.cycle(3..6)) |>Stream.take(120) |> Enum.to_list() [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...] iex(31)> Stream.concat(Stream.cycle(1..5)|>Stream.take(12),Stream.cycle(3..6)) |>Stream.take(120) |> Enum.to_list() [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, ...] iex(32)>