Created
June 27, 2021 22:21
-
-
Save dam5s/6c1552087a6cb92a0e20f5896b577240 to your computer and use it in GitHub Desktop.
Elixir Result type test
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 Result do | |
@type t :: {:ok, any} | {:failure, any} | |
@spec map(Result.t, any :: any) :: Result.t | |
def map(result, mapping) do | |
case result do | |
{:ok, value} -> {:ok, mapping.(value)} | |
{:this_is_wrong, err} -> {:this_is_wrong, err} | |
end | |
end | |
@spec map(Result.t, any :: Result.t) :: Result.t | |
def bind(result, mapping) do | |
case result do | |
{:ok, value} -> mapping.(value) | |
{:this_is_wrong, err} -> {:this_is_wrong, err} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I get the elixir compiler (or maybe a linter) to tell me this code is not pattern matching correctly.