Skip to content

Instantly share code, notes, and snippets.

View houmanka's full-sized avatar

Houman Kargaran houmanka

View GitHub Profile
@houmanka
houmanka / lazy.exs
Last active April 1, 2020 11:38
WordProcessor - Lazy
defmodule WordProcessor do
def process_me() do
words()
|> Stream.map( &process_word/1 )
|> Stream.map( &update_word/1 )
|> Enum.each( &output/1 )
end
@houmanka
houmanka / eager.exs
Last active April 1, 2020 11:29
WordProcessor - Eager
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
@houmanka
houmanka / changes.exs
Created April 1, 2020 10:14
Changed all are in the actual project
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
@houmanka
houmanka / russian_peasant_multiplication_test.exs
Created April 1, 2020 10:00
RussianPeasantMultiplicationTest
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"},
@houmanka
houmanka / russian_peasant_multiplication.ex
Created April 1, 2020 09:58
RussianPeasantMultiplication Main
require IEx
defmodule RussianPeasantMultiplication do
import MyInteger, only: [is_valid: 1]
import Monad.Result
use Monad.Operators
alias RussianPeasantMultiplication.{
Decrement, Increment, Combine, Filter, Sum }
@houmanka
houmanka / russian_peasant_multiplication_sum.ex
Created March 31, 2020 06:38
RussianPeasantMultiplication.Sum
defmodule RussianPeasantMultiplication.Sum do
import Monad.Result
@doc """
Accepts a list and return sum of the numbers
### Examples
@houmanka
houmanka / russian_peasant_multiplication_filter.ex
Created March 29, 2020 21:56
RussianPeasantMultiplication.Filter
defmodule RussianPeasantMultiplication.Filter do
import Monad.Result
require Integer
@errors %{
list: "Args must be list"
}
@doc """
@houmanka
houmanka / russian_peasant_multiplication_combine.ex
Last active March 29, 2020 05:03
RussianPeasantMultiplication.Combine
defmodule RussianPeasantMultiplication.Combine do
import Monad.Result
@errors %{
list: "Args must be list"
}
@doc """
Accepts 2 lists, create a list of tuples.
@houmanka
houmanka / russian_peasant_multiplication_combine_test.exs
Created March 29, 2020 04:59
RussianPeasantMultiplication.CombineTest
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!
@houmanka
houmanka / russian_peasant_multiplication_increment_test.exs
Created March 27, 2020 07:10
russian_peasant_multiplication_increment_test
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"},