Skip to content

Instantly share code, notes, and snippets.

@dam5s
Created June 27, 2021 22:21
Show Gist options
  • Save dam5s/6c1552087a6cb92a0e20f5896b577240 to your computer and use it in GitHub Desktop.
Save dam5s/6c1552087a6cb92a0e20f5896b577240 to your computer and use it in GitHub Desktop.
Elixir Result type test
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
@dam5s
Copy link
Author

dam5s commented Jun 27, 2021

How do I get the elixir compiler (or maybe a linter) to tell me this code is not pattern matching correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment