-
Notifications
You must be signed in to change notification settings - Fork 15
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
Brooklyn Zelenka
committed
Sep 12, 2016
1 parent
bf072a9
commit c1498bb
Showing
9 changed files
with
167 additions
and
24 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
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
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
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
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,66 @@ | ||
defmodule Quark.Pointfree do | ||
@moduledoc ~S""" | ||
Allows defining functions as straight function composition | ||
(ie: no need to state the argument). | ||
Provides a clean, composable named functions | ||
""" | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
require unquote(__MODULE__) | ||
import unquote(__MODULE__) | ||
end | ||
end | ||
|
||
@doc ~S""" | ||
Define a unary function with an implied subject | ||
## Examples | ||
iex> defmodule Foo do | ||
...> use Quark.Pointfree | ||
...> defx foo(), do: Enum.sum |> fn x -> x + 1 end.() | ||
...> end | ||
...> Foo.foo([1,2,3]) | ||
7 | ||
iex> defmodule Bar do | ||
...> use Quark.Pointfree | ||
...> defx bar, do: Enum.sum |> fn x -> x + 1 end.() | ||
...> end | ||
...> Bar.bar([1,2,3]) | ||
7 | ||
""" | ||
defmacro defx(head, do: body) do | ||
{fun_name, ctx, _} = head | ||
|
||
quote do | ||
def unquote({fun_name, ctx, [{:subject, [], Elixir}]}) do | ||
unquote({:subject, [], Elixir}) |> unquote(body) | ||
end | ||
end | ||
end | ||
|
||
@doc ~S""" | ||
Define a private unary function with an implied subject | ||
## Examples | ||
defmodule Foo do | ||
use Quark.Pointfree | ||
defxp foo(), do: Enum.sum |> fn x -> x + 1 end.() | ||
end | ||
""" | ||
defmacro defxp(head, do: body) do | ||
{fun_name, ctx, []} = head | ||
|
||
quote do | ||
defp unquote({fun_name, ctx, [{:subject, [], Elixir}]}) do | ||
unquote({:subject, [], Elixir}) |> unquote(body) | ||
end | ||
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
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
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
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,13 +1,15 @@ | ||
defmodule QuarkTest do | ||
use ExUnit.Case, async: true | ||
use ExUnit.Case, async: false # true | ||
|
||
doctest Quark, import: true | ||
|
||
doctest Quark.BCKW, import: true | ||
doctest Quark.Compose, import: true | ||
doctest Quark.Curry, import: true | ||
doctest Quark.FixedPoint, import: true | ||
doctest Quark.M, import: true | ||
doctest Quark.Partial, import: true | ||
doctest Quark.Sequence, import: true | ||
doctest Quark.Pointfree, import: true | ||
doctest Quark.Sequence.Integer, import: true | ||
doctest Quark.SKI, import: true | ||
end |