Elixir (programming language): Difference between revisions

Content deleted Content added
Line 96:
[1, 9, 25]
</syntaxhighlight>
 
 
Multiple function bodies with [[Guard (computer science)#Mathematics|guards]]
<syntaxhighlight lang="elixir">
def fib(n) when n in [0, 1] do: n
def fib(n), do: fib(n-2) + fib(n-1)
</syntaxhighlight>
 
Relational database access with the Ecto library:
<syntaxhighlight lang="elixir">
schema "weather" do
field :city # Defaults to type :string
field :temp_lo, :integer
field :temp_hi, :integer
field :prcp, :float, default: 0.0
end
 
Weather |> where(city: "Kraków") |> order_by(:temp_lo) |> limit(10) |> Repo.all
</syntaxhighlight>