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
| twenty_four = 24 | |
| not_true = false | |
| API_KEY = 'abc123' |
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
| var twentyFour = 24; | |
| let notTrue = false; | |
| const API_KEY = 'abc123'; |
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
| # Lambdas with one parameter | |
| [1, 2, 3] |> Enum.map(fn x -> x * x end) # [1, 4, 9] | |
| # Lambdas with multiple parameters | |
| [1, 2, 3] |> Enum.reduce(fn x, s -> x + s end) # 6 |
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
| public class AnnotationExample { | |
| @Override | |
| public String toString() { | |
| return "AnnotationExample"; | |
| } | |
| } |
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
| defmodule Math do | |
| @spec add(number, number) :: number | |
| def add(a, b), do: a + b | |
| end |
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
| defmodule Greet do | |
| def hey(name) when is_atom(name) do | |
| name |> to_string |> hey | |
| end | |
| def hey(name) when is_binary(name) do | |
| IO.puts "Hello, " <> name | |
| end | |
| end |
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
| const fibonacci = (n) => { | |
| if (n < 0) { | |
| return null; | |
| } else if (n == 0 || n == 1) { | |
| return 1; | |
| } else { | |
| return fibonacci(n - 1) + fibonacci(n - 2); | |
| } | |
| }; |
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
| defmodule Fib do | |
| def fibonacci(0), do: 1 | |
| def fibonacci(1), do: 1 | |
| def fibonacci(n) when n > 1 do | |
| fibonacci(n-1) + fibonacci(n - 2) | |
| end | |
| def fibonacci(_), do: nil | |
| end |
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
| # Lambdas with one parameter | |
| [1, 2, 3] |> Enum.map(&(&1 * &1)) # [1, 4, 9] | |
| # Lambdas with multiple parameters | |
| [1, 2, 3] |> Enum.reduce(&(&1 + &2)) # 6 |
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
| // Arrow functions with one parameter | |
| [1, 2, 3].map(x => x * x); // [1, 4, 9] | |
| // Arrow functions with multiple parameters | |
| [1, 2, 3].reduce((x, s) => s + x); // 6 |