Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/natserract/lamblichus
Functors macros in Elixir inspired from haskell, and purescript
https://github.com/natserract/lamblichus
elixir functors haskell macro metaprogramming
Last synced: about 2 months ago
JSON representation
Functors macros in Elixir inspired from haskell, and purescript
- Host: GitHub
- URL: https://github.com/natserract/lamblichus
- Owner: natserract
- License: mit
- Created: 2022-05-02T09:03:30.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-03T09:47:41.000Z (almost 3 years ago)
- Last Synced: 2024-04-28T06:27:29.925Z (9 months ago)
- Topics: elixir, functors, haskell, macro, metaprogramming
- Language: Elixir
- Homepage: https://hex.pm/packages/lamblichus
- Size: 6.73 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Lamblichus
Lamblichus is a **elixir [macro](https://elixir-lang.org/getting-started/meta/macros.html)** for implemented [functor](https://www.haskellforall.com/2012/09/the-functor-design-pattern.html), like in haskell
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `lamblichus` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:lamblichus, "~> 0.1.0"}
]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at .Haskell ways:
```hs
~ (+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:
```ex
~ 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:
- [https://shane.logsdon.io/writing/functors-applicatives-and-monads-in-elixir/](https://shane.logsdon.io/writing/functors-applicatives-and-monads-in-elixir/)
- [https://hexdocs.pm/elixir/Module.html#module-compile-callbacks](https://hexdocs.pm/elixir/Module.html#module-compile-callbacks)
- [https://coder-question.com/cq-blog/318128](https://coder-question.com/cq-blog/318128)
- [https://brooklinmyers.medium.com/using-use-usefully-in-elixir-and-phoenix-b59a5ea08ad2](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](https://github.com/elixir-lang/elixir/blob/main/lib/elixir/src/elixir_parser.yrl)