This file contains 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 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 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 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 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 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 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 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. |
This file contains 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.CombineTest do | |
use ExUnit.Case | |
doctest RussianPeasantMultiplication.Combine | |
import Monad.Result | |
alias RussianPeasantMultiplication.Combine, as: Combine | |
test "needs to create tuple from 2 lists" do | |
res = Combine.combine([13, 6, 3, 1], [238, 476, 952, 1904]) |> unwrap! |
This file contains 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.IncrementTest do | |
use ExUnit.Case | |
doctest RussianPeasantMultiplication.Increment | |
import Monad.Result | |
alias RussianPeasantMultiplication.Increment, as: RPM_Inc | |
test "max number must be a number" do | |
items = [ %{requested: "238", max_round: "4"}, | |
%{requested: 238, max_round: "4"}, |
NewerOlder