Skip to content

fehu/elixir-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cat

Category Theory Abstractions

Inspired by cats library in Scala.

Monadic Syntax

Macro Syntax.monadic rewrites with clauses to nested Functor.map and Monad.flat_map applications. If clause has else expression, it's mapped to ``MonadError.recover`.

Syntax.monadic do
  with a <- Either.right(1),
       _ = IO.puts("x1 = #{a}"),
       b <- Either.left("!"),
       _ = IO.puts("b = #{b}")
    do a + b
  else
    failure ->
      IO.puts(failure)
      Either.right("-")
  end
end

Is rewritten to

MonadError.recover(Monad.flat_map(Either.right(1), fn a ->
  IO.puts("x1 = \#{a}")
  Functor.map(Either.left("!"), fn b ->
    IO.puts("b = \#{b}")
    a + b
  end)
end), fn failure ->
  IO.puts(failure)
  Either.right("-")
end)

Protocols

Delegates




Data

About

Category Theory Abstractions for Elixir

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages