Lamblichus is a elixir macro for implemented functor, like in haskell
If available in Hex, the package can be installed
by adding lamblichus
to your list of dependencies in mix.exs
:
def deps do
[
{:lamblichus, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/lamblichus.
Haskell ways:
~ (+1) <$> [1, 2, 3, 4]
-- Output: [2, 3, 4, 5]
~ (\x -> Just x) <$> [1, 2, 3, 4, 5]
-- Output: [Just 1,Just 2,Just 3,Just 4,Just 5]
~ ((\a -> a + 1) <$> (\b -> b * 2)) 8
-- Output: 17
~ ((\a -> a + 1) <&> (\b -> b * 2)) 8
-- Output: 18
~ functor (fn n -> n * 2 end), [1, 2, 3] # Output: [2, 4, 6]
~ (fn n -> n * 2 end) <~> [1, 2, 3] # Output: [2, 4, 6]
~ (functor (fn n -> n + 1 end), (fn n -> n * 2 end)).(8) # Output: 17
~ ((fn n -> n + 1 end) <~> (fn n -> n * 2 end)).(8) # Output: 17
~ functor_flipped [1, 2, 3], (fn n -> n + 1 end) # Output: [2, 3, 4]
~ [1, 2, 3] <|> fn n -> n + 1 end # Output: [2, 3, 4]
~ (functor_flipped (fn n -> n + 1 end), (fn n -> n * 2 end)).(8) # Output: 18
~ ((fn n -> n + 1 end) <|> (fn n -> n * 2 end)).(8) # Output: 18
~ fmap (fn n -> n * 2 end), [1, 2, 3] # Output: [2, 4, 6]
~ flip ((fn n -> n + 1 end), (fn n -> n * 2 end)).(8) # Output: 18
- https://shane.logsdon.io/writing/functors-applicatives-and-monads-in-elixir/
- https://hexdocs.pm/elixir/Module.html#module-compile-callbacks
- https://coder-question.com/cq-blog/318128
- https://brooklinmyers.medium.com/using-use-usefully-in-elixir-and-phoenix-b59a5ea08ad2
- https://github.com/elixir-lang/elixir/blob/main/lib/elixir/src/elixir_parser.yrl