Skip to content

Commit

Permalink
Configure formatter (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
expede authored Jun 15, 2018
1 parent 44d0c3f commit 1cb5930
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 230 deletions.
15 changes: 15 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Used by "mix format"
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [
let: 1
],
export: [
let: 1
],
import_deps: [
:operator,
:quark,
:type_class
]
]
10 changes: 5 additions & 5 deletions lib/witchcraft.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ defmodule Witchcraft do

defmacro __using__(opts \\ []) do
quote do
use Witchcraft.Arrow, unquote(opts)
use Witchcraft.Monoid, unquote(opts)
use Witchcraft.Bifunctor, unquote(opts)
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)
use Witchcraft.Monad, unquote(opts)
use Witchcraft.Comonad, unquote(opts)
end
end
end
6 changes: 3 additions & 3 deletions lib/witchcraft/applicative.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defclass Witchcraft.Applicative do

defmacro __using__(opts \\ []) do
quote do
use Witchcraft.Apply, unquote(opts)
use Witchcraft.Apply, unquote(opts)
import unquote(__MODULE__), unquote(opts)
end
end
Expand Down Expand Up @@ -179,7 +179,7 @@ defclass Witchcraft.Applicative do
a = generate(data)
f = &inspect/1

left = Applicative.of(a, arg) ~>> Applicative.of(a, f)
left = Applicative.of(a, arg) ~>> Applicative.of(a, f)
right = Applicative.of(a, f.(arg))

equal?(left, right)
Expand All @@ -190,7 +190,7 @@ defclass Witchcraft.Applicative do
as = generate(data)
fs = replace(as, &inspect/1)

left = Applicative.of(as, arg) ~>> fs
left = Applicative.of(as, arg) ~>> fs
right = fs ~>> Applicative.of(as, fn g -> g.(arg) end)

equal?(left, right)
Expand Down
41 changes: 22 additions & 19 deletions lib/witchcraft/apply.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ defclass Witchcraft.Apply do
extend Witchcraft.Functor
use Witchcraft.Functor

@type t :: any()
@type t :: any()
@type fun :: any()

defmacro __using__(opts \\ []) do
quote do
use Witchcraft.Functor, unquote(opts)
use Witchcraft.Functor, unquote(opts)
import unquote(__MODULE__), unquote(opts)
end
end
Expand Down Expand Up @@ -159,13 +159,13 @@ defclass Witchcraft.Apply do
fs = data |> generate() |> Functor.replace(fn x -> x <> x end)
gs = data |> generate() |> Functor.replace(fn y -> y <> "foo" end)

left = Apply.convey(Apply.convey(as, gs), fs)
left = Apply.convey(Apply.convey(as, gs), fs)

right =
fs
|> Functor.lift(&compose/2)
|> fn x -> Apply.convey(gs, x) end.()
|> fn y -> Apply.convey(as, y) end.()
|> (fn x -> Apply.convey(gs, x) end).()
|> (fn y -> Apply.convey(as, y) end).()

equal?(left, right)
end
Expand Down Expand Up @@ -223,7 +223,7 @@ defclass Witchcraft.Apply do
"""
@spec ap(Apply.fun(), Apply.t()) :: Apply.t()
def ap(wrapped_funs, wrapped) do
lift(wrapped, wrapped_funs, fn(arg, fun) -> fun.(arg) end)
lift(wrapped, wrapped_funs, fn arg, fun -> fun.(arg) end)
end

@doc """
Expand Down Expand Up @@ -253,11 +253,13 @@ defclass Witchcraft.Apply do
@spec async_convey(Apply.t(), Apply.fun()) :: Apply.t()
def async_convey(wrapped_args, wrapped_funs) do
wrapped_args
|> convey(lift(wrapped_funs, fn(fun, arg) ->
Task.async(fn ->
fun.(arg)
|> convey(
lift(wrapped_funs, fn fun, arg ->
Task.async(fn ->
fun.(arg)
end)
end)
end))
)
|> map(&Task.await/1)
end

Expand Down Expand Up @@ -287,7 +289,7 @@ defclass Witchcraft.Apply do
@spec async_ap(Apply.fun(), Apply.t()) :: Apply.t()
def async_ap(wrapped_funs, wrapped_args) do
wrapped_funs
|> lift(fn(fun, arg) ->
|> lift(fn fun, arg ->
Task.async(fn ->
fun.(arg)
end)
Expand Down Expand Up @@ -437,7 +439,7 @@ defclass Witchcraft.Apply do
def lift(a, b, fun) do
a
|> lift(fun)
|> fn f -> convey(b, f) end.()
|> (fn f -> convey(b, f) end).()
end

@doc """
Expand Down Expand Up @@ -481,7 +483,7 @@ defclass Witchcraft.Apply do
def async_lift(a, b, fun) do
a
|> async_lift(fun)
|> fn f -> async_convey(b, f) end.()
|> (fn f -> async_convey(b, f) end).()
end

@doc """
Expand Down Expand Up @@ -600,7 +602,7 @@ end

definst Witchcraft.Apply, for: List do
def convey(val_list, fun_list) when is_list(fun_list) do
Enum.flat_map(val_list, fn(val) ->
Enum.flat_map(val_list, fn val ->
Enum.map(fun_list, fn fun -> fun.(val) end)
end)
end
Expand All @@ -615,9 +617,10 @@ definst Witchcraft.Apply, for: Tuple do
{generate(""), generate(1), generate(0), generate(""), generate(""), generate("")}
end

def convey({v, w}, {a, fun}), do: {v <> a, fun.(w)}
def convey({v, w, x}, {a, b, fun}), do: {v <> a, w <> b, fun.(x)}
def convey({v, w, x, y}, {a, b, c, fun}), do: {v <> a, w <> b, x <> c, fun.(y)}
def convey({v, w}, {a, fun}), do: {v <> a, fun.(w)}
def convey({v, w, x}, {a, b, fun}), do: {v <> a, w <> b, fun.(x)}
def convey({v, w, x, y}, {a, b, c, fun}), do: {v <> a, w <> b, x <> c, fun.(y)}

def convey({v, w, x, y, z}, {a, b, c, d, fun}) do
{
a <> v,
Expand All @@ -636,8 +639,8 @@ definst Witchcraft.Apply, for: Tuple do
|> Enum.zip(Tuple.to_list(tuple_b))
|> Enum.with_index()
|> Enum.map(fn
{{arg, fun}, ^last_index} -> fun.(arg)
{{left, right}, _} -> left <> right
{{arg, fun}, ^last_index} -> fun.(arg)
{{left, right}, _} -> left <> right
end)
|> List.to_tuple()
end
Expand Down
Loading

0 comments on commit 1cb5930

Please sign in to comment.