PatternMetonyms.view

You're seeing just the macro view, go back to PatternMetonyms module for more information.
Link to this macro

view(expr, clauses)

View Source (macro)

Macro substitute for case/2 capable of using pattern metonyms.

Custom case able to use pattern metonyms defined with this module. Largely unoptimized, try to avoid side effect in your pattern definitions as using them multiple time in view will repeat them, but might not later on.

View pattern ((function -> pattern)) may be used raw in here.

View patterns are simply a pair of a function associated with a pattern where the function will be applied to the data passed to view and the result will be matched with the pattern.

iex> import PatternMetonyms
iex> view self() do
...>   (is_pid() -> true) -> :ok
...>   _ -> :ko
...> end
:ok

Guards can be used outside of the view pattern or the pattern metonym.

iex> import PatternMetonyms
iex> view -3 - :rand.uniform(2) do
...>   (abs() -> x) when x > 3 -> :ok
...>   (abs() -> x) when x < 3 -> :ko
...>   x -> x
...> end
:ok

Remote calls can be used directly within a view pattern.

iex> import PatternMetonyms
iex> view :banana do
...>   (Atom.to_string() -> "ba" <> _) -> :ok
...>   _ -> :ko
...> end
:ok

Anonymous functions can be used within a view pattern. They can be either used as stored within a variable:

iex> import PatternMetonyms
iex> fun = &inspect(&1, pretty: &2)
iex> view :banana do
...>   (fun.(true) -> str) -> str
...> end
":banana"

Or defined directly using Kernel.SpecialForms.fn/1 only:

iex> import PatternMetonyms
iex> view 3 do
...>   (fn x -> x + 2 end -> n) -> n + 1
...> end
6