-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major improvements to structure, docs, and tests - Added Semigroupoid -> Category -> Arrow - Added Foldable -> Traversable - Added Extend -> Comonad - Added Bifunctor - Fixed do-notation - Split `chain do` and `monad _ do`
- Loading branch information
Showing
43 changed files
with
3,880 additions
and
843 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: elixir | ||
elixir: | ||
- 1.3.2 | ||
- 1.5.0 | ||
otp_release: | ||
- 19.0.2 | ||
- 20.0 | ||
script: mix test; mix credo --strict | ||
after_script: | ||
- MIX_ENV=docs mix do deps.get, inch.report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
 | ||
 | ||
|
||
`Witchcraft` is a library providing common algebraic and categorical abstractions to Elixir. | ||
(Monoids, functors, monads, arrows, and categories) | ||
|
@@ -7,7 +7,8 @@ | |
|
||
A big thank you to [Brandon Labbé](https://dribbble.com/brandonlabbe) for creating the logo to this project | ||
|
||
# Table of Contents | ||
# README | ||
## Table of Contents | ||
- [Quick Start](#quick-start) | ||
- [Values](#values) | ||
- [Beginner Friendliness](#beginner-friendliness) | ||
|
@@ -30,6 +31,59 @@ def deps do | |
end | ||
``` | ||
|
||
# Relationship to Other Packages | ||
``` | ||
Quark TypeClass | ||
↘ ↙ | ||
Witchcraft | ||
↓ | ||
Algae | ||
``` | ||
|
||
* [Quark](https://hex.pm/packages/quark): Standard combinators (`id`, `compose`, &c) | ||
* [TypeClass](https://hex.pm/packages/type_class): Used internally to generate type classes | ||
* [Algae](https://hex.pm/packages/algae): Algebraic data types that implement Witchcraft type classes | ||
|
||
# Hierarchy | ||
|
||
``` | ||
Semigroupoid Semigroup Setoid Foldable Functor -----------┐ | ||
↓ ↓ ↓ ↓ ↙ ↓ ↘ | | ||
Category Monoid Ord Traversable Apply Bifunctor | | ||
↓ ↙ ↘ ↓ | ||
Arrow Applicative Chain Extend | ||
↘ ↙ ↓ | ||
Monad Comonad | ||
``` | ||
|
||
It is very common to want everything in a chain. You can import the entire chain | ||
with `use`. For example: | ||
|
||
```elixir | ||
use Witchcraft.Monad | ||
``` | ||
|
||
Any options that you pass to `use` will be propagated all the way down the chain | ||
|
||
```elixir | ||
use Witchcraft.Monad, except: [~>: 2] | ||
``` | ||
|
||
Some modules override `Kernel` operators and functions. While this is generally safe, | ||
if you would like to skip all overrides, pass `override_kernel: false` as an option | ||
|
||
```elixir | ||
use Witchcraft.Foldable, override_kernel: false | ||
``` | ||
|
||
Finally, to import the entire library: | ||
|
||
```elixir | ||
use Witchcraft | ||
``` | ||
|
||
# Values | ||
## Beginner Friendliness | ||
As much as possible, keep things friendly. Concrete examples are available in the | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
defmodule Witchcraft do | ||
@moduledoc "Convenient top-level `use`" | ||
@moduledoc """ | ||
Top level module | ||
defmacro __using__(_) do | ||
quote do | ||
use Witchcraft.Monoid | ||
## Hierarchy | ||
Semigroupoid Semigroup Setoid Foldable Functor -----------┐ | ||
↓ ↓ ↓ ↓ ↙ ↓ ↘ | | ||
Category Monoid Ord Traversable Apply Bifunctor | | ||
↓ ↙ ↘ ↓ | ||
Arrow Applicative Chain Extend | ||
↘ ↙ ↓ | ||
Monad Comonad | ||
## `use Wicthcraft` | ||
There is a convenient `use` macro to import *all* functions in the library. | ||
use Witchcraft | ||
This recursively calls `use` on all children modules. | ||
use Witchcraft.Functor | ||
use Witchcraft.Traversable | ||
use Witchcraft.Applicative | ||
use Witchcraft.Monad | ||
Any options passed to `use` will be passed down to all dependencies. | ||
use Witchcraft, execpt: [right_fold: 2] | ||
If you would like to not override the functions and operators from `Kernel`, | ||
you can pass the special option `override_kernel: false`. | ||
use Witchcraft, override_kernel: false | ||
This same style of `use` is also available on all submodules, and follow | ||
the dependency chart (above). | ||
""" | ||
|
||
defmacro __using__(opts \\ []) do | ||
quote do | ||
use Witchcraft.Arrow, unquote(opts) | ||
use Witchcraft.Monoid, unquote(opts) | ||
use Witchcraft.Bifunctor, unquote(opts) | ||
use Witchcraft.Traversable, unquote(opts) | ||
use Witchcraft.Monad, unquote(opts) | ||
use Witchcraft.Comonad, unquote(opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.