From 05121bf808e0ccc3efd2a6ade55035ad0affe075 Mon Sep 17 00:00:00 2001 From: Antonio Ognio Date: Tue, 16 Feb 2016 12:38:53 -0500 Subject: Fixing broken link to Elixir's Getting Started documentation --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 720e080c..bf3c42a6 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -411,7 +411,7 @@ self() #=> #PID<0.27.0> ## References -* [Getting started guide](http://elixir-lang.org/getting_started/1.html) from [elixir webpage](http://elixir-lang.org) +* [Getting started guide](http://elixir-lang.org/getting-started/introduction.html) from the [Elixir website](http://elixir-lang.org) * [Elixir Documentation](http://elixir-lang.org/docs/master/) * ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) by Dave Thomas * [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf) -- cgit v1.2.3 From d88564513fa334263e9e1a03d98f1f9d766c6bca Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Young Date: Fri, 4 Mar 2016 11:02:20 -0500 Subject: Update elixir.html.markdown The variable is only bound in the case statements --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index bf3c42a6..eb708576 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -170,7 +170,7 @@ case {:one, :two} do {:four, :five} -> "This won't match" {:one, x} -> - "This will match and bind `x` to `:two`" + "This will match and bind `x` to `:two` in this clause" _ -> "This will match any value" end -- cgit v1.2.3 From e249d12ee6fdc9366e6d13b869f2ca2ccff6ee56 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 12 Jul 2016 18:07:38 +1000 Subject: Elixir agents/maps, Ruby conventions/docs (#2116) * Add name to contributors list * Fix typo * Note convention on curly-braced blocks * Replace hardcoded link to 2.1.1 documentation with generic current link * Add notes on Elixir agents * Add explanation of maps * Add name to contributors list * Fix code fence that was obscuring markdown * Fix syntax error * Remove disputed comment * Remove from contributors list --- elixir.html.markdown | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index eb708576..26a547c3 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -3,6 +3,7 @@ language: elixir contributors: - ["Joao Marques", "http://github.com/mrshankly"] - ["Dzianis Dashkevich", "https://github.com/dskecse"] + - ["Ryan Plant", "https://github.com/ryanplant-au"] filename: learnelixir.ex --- @@ -96,6 +97,14 @@ string. lower..upper = 1..10 # Can use pattern matching on ranges as well [lower, upper] #=> [1, 10] +# Maps are key-value pairs +genders = %{"david" => "male", "gillian" => "female"} +genders["david"] #=> "male" + +# Maps with atom keys can be used like this +genders = %{david: "male", gillian: "female"} +genders.gillian #=> "female" + ## --------------------------- ## -- Operators ## --------------------------- @@ -407,6 +416,23 @@ send pid, {:circle, 2} # The shell is also a process, you can use `self` to get the current pid self() #=> #PID<0.27.0> + +## --------------------------- +## -- Agents +## --------------------------- + +# An agent is a process that keeps track of some changing value + +# Create an agent with `Agent.start_link`, passing in a function +# The initial state of the agent will be whatever that function returns +{ok, my_agent} = Agent.start_link(fn -> ["red, green"] end) + +# `Agent.get` takes an agent name and a `fn` that gets passed the current state +# Whatever that `fn` returns is what you'll get back +Agent.get(my_agent, fn colors -> colors end) #=> ["red, "green"] + +# Update the agent's state the same way +Agent.update(my_agent, fn colors -> ["blue" | colors] end) ``` ## References -- cgit v1.2.3 From da26d353ae2a32edc1509049a18160bf33d07d1e Mon Sep 17 00:00:00 2001 From: chriszimmerman Date: Sun, 9 Oct 2016 07:28:23 -0400 Subject: [elixir/en] Adds elixir documentation on the pipe operator. (#2434) --- elixir.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 26a547c3..63b7aef2 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -325,6 +325,14 @@ defmodule MyMod do IO.inspect(@my_data) #=> 100 end +# The pipe operator |> allows you to pass the output of an expression +# as the first parameter into a function. + +Range.new(1,10) +|> Enum.map(fn x -> x * x end) +|> Enum.filter(fn x -> rem(x, 2) == 0 end) +#=> [4, 16, 36, 64, 100] + ## --------------------------- ## -- Structs and Exceptions ## --------------------------- -- cgit v1.2.3 From 2b4fe43f7187fcc3df0772a36f4264269f98c5c1 Mon Sep 17 00:00:00 2001 From: Jonah Hirsch Date: Wed, 15 Mar 2017 02:06:31 -0700 Subject: Fix some missing double quotes in Agent section (#2682) --- elixir.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 63b7aef2..9dfffc41 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -433,11 +433,11 @@ self() #=> #PID<0.27.0> # Create an agent with `Agent.start_link`, passing in a function # The initial state of the agent will be whatever that function returns -{ok, my_agent} = Agent.start_link(fn -> ["red, green"] end) +{ok, my_agent} = Agent.start_link(fn -> ["red", "green"] end) # `Agent.get` takes an agent name and a `fn` that gets passed the current state # Whatever that `fn` returns is what you'll get back -Agent.get(my_agent, fn colors -> colors end) #=> ["red, "green"] +Agent.get(my_agent, fn colors -> colors end) #=> ["red", "green"] # Update the agent's state the same way Agent.update(my_agent, fn colors -> ["blue" | colors] end) -- cgit v1.2.3