forked from witchcrafters/witchcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
2 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,3 +1,13 @@ | ||
defmodule Witchcraft.Arrow do | ||
defprotocol Witchcraft.Arrow do | ||
@type arrow :: {any, any, any} | ||
@type split :: {any, any} | ||
|
||
@spec arr((any -> any)) :: arrow | ||
def arr(b->c) | ||
|
||
@spec first(arrow) :: arrow | ||
def first(arrow) | ||
|
||
@spec second(arrow) :: arrow | ||
def second(arrow) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Witchcraft.Arrow.Extra do | ||
alias Witchcraft.Category, as: C | ||
alias Witchcraft.Arrow, as: A | ||
|
||
@spec product(arrow, arrow) :: arrow | ||
def product(f, g) do | ||
C.compose_left_to_right(A.first(f), A.second(g)) | ||
end | ||
|
||
@spec fanout(arrow, arrow) :: arrow | ||
def fanout(f, g) do | ||
A.arr &({&1, &1}) | ||
|> C.compose_left_to_right(product(f,g)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defprotocol Witchcraft.Category do | ||
def id | ||
def compose | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Witchcraft.Category.Extra do | ||
alias Witchcraft.Category, as: C | ||
|
||
def compose_left_to_right(a->b, b->c) do | ||
&(&1 |> C.compose(a->b) |> C.compose(b->c)) | ||
end | ||
|
||
def compose_right_to_left(b->c, a->b) do | ||
&(&1 |> C.compose(a->b) |> C.compose(b->c)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
defmodule Witchcraft.Monad do | ||
defprotocol Witchcraft.Monad do | ||
|
||
@spec return(any) :: any | ||
def return(bare) | ||
|
||
@spec bind(any, (any -> any)) :: any | ||
def bind(wrapped_element, wrapping_func) | ||
|
||
@spec then(any, any) :: any | ||
def then(wrapped_element, wrapped_element) | ||
end |