Skip to content

natserract/lamblichus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lamblichus

Lamblichus is a elixir macro for implemented functor, like in haskell

Installation

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

Example:

~ 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

References:

About

Functors macros in Elixir inspired from haskell, and purescript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages