Last active
July 10, 2017 13:24
-
-
Save rakibulislam/8d3a394a4f5fc4e36e96b0e373e6f4c3 to your computer and use it in GitHub Desktop.
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
| # fibonacci | |
| # https://stackoverflow.com/questions/44837662/named-anonymous-functions-in-elixir/44837880#44837880 | |
| defmodule Fibonacci do | |
| def get(n) when n <= 1, do: 1 | |
| def get(n), do: get(n-1) + get(n-2) | |
| end | |
| # Elixir how to iterate over two lists at once to produce a new list? | |
| # https://stackoverflow.com/questions/44938494/elixir-how-to-iterate-over-two-lists-at-once-to-produce-a-new-list/44940454#44940454 | |
| list_of_maps | |
| |> Enum.zip(list_of_items) | |
| |> Enum.map(fn {map, item} -> | |
| if (map["b"] == "0"), do: map, else: Map.put(map, "a", item) | |
| end) | |
| Another way: | |
| for {map, item} <- Enum.zip(list_of_maps, list_of_items), | |
| into: [], | |
| do: if (map["b"] == "0"), do: map, else: %{map | "a" => item} | |
| # Recursion and anonymous functions in elixir | |
| # https://stackoverflow.com/questions/21982713/recursion-and-anonymous-functions-in-elixir?noredirect=1&lq=1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment