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
| # Usage: | |
| # !git clone https://gist.github.com/d828518b070af514c339d9efa548f525.git gist_code | |
| # !ls -la gist_code | |
| # import glob, importlib.util, sys | |
| # | |
| # helper_path = glob.glob("gist_code/*.py")[0] | |
| # spec = importlib.util.spec_from_file_location("helpers", helper_path) | |
| # helpers = importlib.util.module_from_spec(spec) | |
| # sys.modules["helpers"] = helpers | |
| # spec.loader.exec_module(helpers) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 WordProcessor do | |
| def process_me() do | |
| words() | |
| |> Stream.map( &process_word/1 ) | |
| |> Stream.map( &update_word/1 ) | |
| |> Enum.each( &output/1 ) | |
| 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 WordProcessor do | |
| def process_me() do | |
| words() | |
| |> Enum.map( &process_word/1 ) | |
| |> Enum.map( &update_word/1 ) | |
| |> Enum.each( &output/1 ) | |
| end | |
| def process_word(word) do |
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
| def decrement(%Monad.Result{type: :ok} = state) do | |
| state.value | |
| |> decrement | |
| end | |
| def increment( | |
| %Monad.Result{type: :ok} = first, | |
| %Monad.Result{type: :ok} = second ) do | |
| second = second.value |> Enum.count | |
| increment(first.value, second) | |
| 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 RussianPeasantMultiplicationTest do | |
| use ExUnit.Case | |
| doctest RussianPeasantMultiplication | |
| alias RussianPeasantMultiplication, as: RPM | |
| test "Should return errors if inputs are incorrect" do | |
| [ | |
| %{first: "we", second: "adf"}, | |
| %{first: 13, second: "adf"}, |
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
| require IEx | |
| defmodule RussianPeasantMultiplication do | |
| import MyInteger, only: [is_valid: 1] | |
| import Monad.Result | |
| use Monad.Operators | |
| alias RussianPeasantMultiplication.{ | |
| Decrement, Increment, Combine, Filter, Sum } |
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 RussianPeasantMultiplication.Sum do | |
| import Monad.Result | |
| @doc """ | |
| Accepts a list and return sum of the numbers | |
| ### Examples |
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 RussianPeasantMultiplication.Filter do | |
| import Monad.Result | |
| require Integer | |
| @errors %{ | |
| list: "Args must be list" | |
| } | |
| @doc """ |
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 RussianPeasantMultiplication.Combine do | |
| import Monad.Result | |
| @errors %{ | |
| list: "Args must be list" | |
| } | |
| @doc """ | |
| Accepts 2 lists, create a list of tuples. |
NewerOlder