From 1cb5930b4aed6b4233750d6684ec79acdf44139e Mon Sep 17 00:00:00 2001 From: Brooklyn Zelenka Date: Fri, 15 Jun 2018 13:12:56 -0700 Subject: [PATCH] Configure formatter (#53) --- .formatter.exs | 15 +++ lib/witchcraft.ex | 10 +- lib/witchcraft/applicative.ex | 6 +- lib/witchcraft/apply.ex | 41 ++++---- lib/witchcraft/arrow.ex | 76 +++++++-------- lib/witchcraft/bifunctor.ex | 6 +- lib/witchcraft/category.ex | 2 +- lib/witchcraft/chain.ex | 18 ++-- lib/witchcraft/comonad.ex | 2 +- lib/witchcraft/extend.ex | 11 ++- lib/witchcraft/foldable.ex | 69 +++++++------- lib/witchcraft/foldable/empty_error.ex | 10 +- lib/witchcraft/functor.ex | 6 +- lib/witchcraft/monad.ex | 6 +- lib/witchcraft/monoid.ex | 4 +- lib/witchcraft/ord.ex | 10 +- lib/witchcraft/ord/bitstring.ex | 4 +- lib/witchcraft/ord/float.ex | 4 +- lib/witchcraft/ord/integer.ex | 4 +- lib/witchcraft/ord/list.ex | 4 +- lib/witchcraft/semigroup.ex | 10 +- lib/witchcraft/semigroupoid.ex | 6 +- lib/witchcraft/setoid.ex | 8 +- lib/witchcraft/traversable.ex | 10 +- mix.exs | 39 +++----- mix.lock | 14 +-- test/do_notation_test.exs | 126 +++++++++++++++++++------ test/witchcraft_test.exs | 20 ++-- 28 files changed, 311 insertions(+), 230 deletions(-) create mode 100644 .formatter.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..9a19728 --- /dev/null +++ b/.formatter.exs @@ -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 + ] +] diff --git a/lib/witchcraft.ex b/lib/witchcraft.ex index 760b2f5..18ca382 100644 --- a/lib/witchcraft.ex +++ b/lib/witchcraft.ex @@ -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 diff --git a/lib/witchcraft/applicative.ex b/lib/witchcraft/applicative.ex index 85520e6..b0fffec 100644 --- a/lib/witchcraft/applicative.ex +++ b/lib/witchcraft/applicative.ex @@ -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 @@ -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) @@ -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) diff --git a/lib/witchcraft/apply.ex b/lib/witchcraft/apply.ex index 9902a09..8fecab3 100644 --- a/lib/witchcraft/apply.ex +++ b/lib/witchcraft/apply.ex @@ -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 @@ -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 @@ -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 """ @@ -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 @@ -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) @@ -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 """ @@ -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 """ @@ -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 @@ -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, @@ -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 diff --git a/lib/witchcraft/arrow.ex b/lib/witchcraft/arrow.ex index e48f8dd..b66e2e7 100644 --- a/lib/witchcraft/arrow.ex +++ b/lib/witchcraft/arrow.ex @@ -45,7 +45,7 @@ defclass Witchcraft.Arrow do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Category, unquote(opts) + use Witchcraft.Category, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -74,7 +74,7 @@ defclass Witchcraft.Arrow do def arrow_identity(sample) do a = generate(nil) - left = Arrow.arrowize(sample, &Quark.id/1) + left = Arrow.arrowize(sample, &Quark.id/1) right = &Quark.id/1 equal?(a |> pipe(left), a |> pipe(right)) @@ -88,20 +88,20 @@ defclass Witchcraft.Arrow do f = fn x -> "#{x}-#{x}" end g = &inspect/1 - left = Arrow.arrowize(sample, f) <|> Arrow.arrowize(sample, g) + left = Arrow.arrowize(sample, f) <|> Arrow.arrowize(sample, g) right = Arrow.arrowize(sample, f <|> g) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def first_commutativity(sample) do - a = {generate(nil), generate(nil)} - f = &inspect/1 + a = {generate(nil), generate(nil)} + f = &inspect/1 - left = Witchcraft.Arrow.first(Arrow.arrowize(sample, f)) - right = Arrow.arrowize(sample, Witchcraft.Arrow.first(f)) + left = Witchcraft.Arrow.first(Arrow.arrowize(sample, f)) + right = Arrow.arrowize(sample, Witchcraft.Arrow.first(f)) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def first_composition(sample) do @@ -110,20 +110,20 @@ defclass Witchcraft.Arrow do f = Arrow.arrowize(sample, fn x -> "#{x}-#{x}" end) g = Arrow.arrowize(sample, &inspect/1) - left = Witchcraft.Arrow.first(f <|> g) + left = Witchcraft.Arrow.first(f <|> g) right = Witchcraft.Arrow.first(f) <|> Witchcraft.Arrow.first(g) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def second_arrow_commutativity(sample) do a = {generate(nil), generate(nil)} f = &inspect/1 - left = Witchcraft.Arrow.second(Arrow.arrowize(sample, f)) + left = Witchcraft.Arrow.second(Arrow.arrowize(sample, f)) right = Arrow.arrowize(sample, Witchcraft.Arrow.second(f)) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def second_composition(sample) do @@ -132,19 +132,19 @@ defclass Witchcraft.Arrow do f = Arrow.arrowize(sample, fn x -> "#{x}-#{x}" end) g = Arrow.arrowize(sample, &inspect/1) - left = Witchcraft.Arrow.second(f <|> g) + left = Witchcraft.Arrow.second(f <|> g) right = Witchcraft.Arrow.second(f) <|> Witchcraft.Arrow.second(g) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def product_composition(sample) do a = {generate(nil), generate(nil)} f = &inspect/1 - g = fn x -> "#{inspect x}-#{inspect x}" end + g = fn x -> "#{inspect(x)}-#{inspect(x)}" end - left = + left = Witchcraft.Arrow.product( Arrow.arrowize(sample, f), Arrow.arrowize(sample, g) @@ -152,16 +152,16 @@ defclass Witchcraft.Arrow do right = Arrow.arrowize(sample, Witchcraft.Arrow.product(f, g)) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def fanout_composition(sample) do a = generate(nil) f = &inspect/1 - g = fn x -> "#{inspect x}-#{inspect x}" end + g = fn x -> "#{inspect(x)}-#{inspect(x)}" end - left = + left = Witchcraft.Arrow.fanout( Arrow.arrowize(sample, f), Arrow.arrowize(sample, g) @@ -169,17 +169,17 @@ defclass Witchcraft.Arrow do right = Arrow.arrowize(sample, Witchcraft.Arrow.fanout(f, g)) - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def first_reassociaton(sample) do a = {{generate(nil), generate(nil)}, {generate(nil), generate(nil)}} - f = fn x -> "#{inspect x}-#{inspect x}" end + f = fn x -> "#{inspect(x)}-#{inspect(x)}" end x = Witchcraft.Arrow.first(Arrow.arrowize(sample, f)) y = Arrow.arrowize(sample, &Witchcraft.Arrow.reassociate/1) - left = Witchcraft.Arrow.first(x) <~> y + left = Witchcraft.Arrow.first(x) <~> y right = y <~> x equal?(a |> pipe(left), a |> pipe(right)) @@ -187,27 +187,27 @@ defclass Witchcraft.Arrow do def first_identity(sample) do a = {generate(nil), generate(nil)} - f = fn x -> "#{inspect x}-#{inspect x}" end + f = fn x -> "#{inspect(x)}-#{inspect(x)}" end - left = Witchcraft.Arrow.first(f) <~> Arrow.arrowize(sample, fn {x, _} -> x end) + left = Witchcraft.Arrow.first(f) <~> Arrow.arrowize(sample, fn {x, _} -> x end) right = Arrow.arrowize(sample, fn {x, _} -> x end) <~> f - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end def first_product_commutativity(sample) do a = {generate(nil), generate(nil)} f = &inspect/1 - g = fn x -> "#{inspect x}-#{inspect x}" end + g = fn x -> "#{inspect(x)}-#{inspect(x)}" end x = Arrow.arrowize(sample, Witchcraft.Arrow.product(&Quark.id/1, g)) y = Witchcraft.Arrow.first(f) - left = x <|> y + left = x <|> y right = y <|> x - equal?(a |> pipe(left), a |> pipe(right)) + equal?(pipe(a, left), pipe(a, right)) end end @@ -228,7 +228,7 @@ defclass Witchcraft.Arrow do """ @spec product(Arrow.t(), Arrow.t()) :: Arrow.t() - def product(arrow_f, arrow_g), do: first(arrow_f) <~> (second(arrow_g)) + def product(arrow_f, arrow_g), do: first(arrow_f) <~> second(arrow_g) @doc """ Alias for `product/2`, meant to invoke a spacial metaphor @@ -281,7 +281,7 @@ defclass Witchcraft.Arrow do """ @spec first(Arrow.t()) :: Arrow.t() def first(arrow) do - arrowize(arrow, fn({x, y}) -> + arrowize(arrow, fn {x, y} -> { x |> pipe(arrow), y |> pipe(id_arrow(arrow)) @@ -300,7 +300,7 @@ defclass Witchcraft.Arrow do """ @spec second(Arrow.t()) :: Arrow.t() def second(arrow) do - arrowize(arrow, fn({x, y}) -> + arrowize(arrow, fn {x, y} -> { x |> pipe(id_arrow(arrow)), y |> pipe(arrow) @@ -338,7 +338,7 @@ defclass Witchcraft.Arrow do """ @spec fanout(Arrow.t(), Arrow.t()) :: Arrow.t() def fanout(arrow_f, arrow_g) do - arrow_f |> arrowize(&split/1) <~> arrow_f ^^^ arrow_g + arrow_f |> arrowize(&split/1) <~> (arrow_f ^^^ arrow_g) end @doc """ @@ -403,7 +403,7 @@ defclass Witchcraft.Arrow do 3 """ - @spec unsplit({any(), any()}, ((any(), any()) -> any())) :: any() + @spec unsplit({any(), any()}, (any(), any() -> any())) :: any() def unsplit({x, y}, combine), do: combine.(x, y) @doc """ @@ -419,9 +419,9 @@ defclass Witchcraft.Arrow do {1, {2, 3}} """ - @spec reassociate({any(), {any(), any()}} | {{any(), any()}, any()}) - :: {{any(), any()}, any()} | {any(), {any(), any()}} - def reassociate({{a, b}, c}), do: {a, {b, c}} + @spec reassociate({any(), {any(), any()}} | {{any(), any()}, any()}) :: + {{any(), any()}, any()} | {any(), {any(), any()}} + def reassociate({{a, b}, c}), do: {a, {b, c}} def reassociate({a, {b, c}}), do: {{a, b}, c} @doc """ @@ -461,5 +461,5 @@ definst Witchcraft.Arrow, for: Function do use Quark def arrowize(_, fun), do: curry(fun) - def first(arrow), do: fn({target, unchanged}) -> {arrow.(target), unchanged} end + def first(arrow), do: fn {target, unchanged} -> {arrow.(target), unchanged} end end diff --git a/lib/witchcraft/bifunctor.ex b/lib/witchcraft/bifunctor.ex index f7cd1a8..d74f540 100644 --- a/lib/witchcraft/bifunctor.ex +++ b/lib/witchcraft/bifunctor.ex @@ -27,7 +27,7 @@ defclass Witchcraft.Bifunctor do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Functor, unquote(opts) + use Witchcraft.Functor, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -80,7 +80,7 @@ defclass Witchcraft.Bifunctor do h = &is_number/1 i = &!/1 - left = a |> Bifunctor.bimap(fn x -> f.(g.(x)) end, fn y -> h.(i.(y)) end) + left = Bifunctor.bimap(a, fn x -> f.(g.(x)) end, fn y -> h.(i.(y)) end) right = a |> Bifunctor.bimap(g, i) |> Bifunctor.bimap(f, h) equal?(left, right) @@ -111,7 +111,7 @@ defclass Witchcraft.Bifunctor do """ @spec map_first(Bifunctor.t(), (any() -> any())) :: Bifunctor.t() - def map_first(data, f), do: Bifunctor.bimap(data, f, &Quark.id/1) + def map_first(data, f), do: Bifunctor.bimap(data, f, &Quark.id/1) @doc """ The same as `map_first`, but with a curried function diff --git a/lib/witchcraft/category.ex b/lib/witchcraft/category.ex index 3c6249e..ffad1ab 100644 --- a/lib/witchcraft/category.ex +++ b/lib/witchcraft/category.ex @@ -29,7 +29,7 @@ defclass Witchcraft.Category do defmacro __using__(opts \\ []) do quote do use Witchcraft.Semigroupoid, unquote(opts) - import unquote(__MODULE__), unquote(opts) + import unquote(__MODULE__), unquote(opts) end end diff --git a/lib/witchcraft/chain.ex b/lib/witchcraft/chain.ex index 6d7ddd5..e9d0975 100644 --- a/lib/witchcraft/chain.ex +++ b/lib/witchcraft/chain.ex @@ -44,7 +44,7 @@ defclass Witchcraft.Chain do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Apply, unquote(opts) + use Witchcraft.Apply, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -205,7 +205,7 @@ defclass Witchcraft.Chain do """ @spec join(Chain.t()) :: Chain.t() - def join(nested), do: nested >>> &Quark.id/1 + def join(nested), do: nested >>> (&Quark.id/1) @spec flatten(Chain.t()) :: Chain.t() defalias flatten(nested), as: :join @@ -415,17 +415,17 @@ defclass Witchcraft.Chain do |> normalize() |> Enum.reverse() |> Witchcraft.Foldable.left_fold(fn - (continue, {:let, _, [{:=, _, [assign, value]}]}) -> - quote do: unquote(value) |> fn unquote(assign) -> unquote(continue) end.() + continue, {:let, _, [{:=, _, [assign, value]}]} -> + quote do: unquote(value) |> (fn unquote(assign) -> unquote(continue) end).() - (continue, {:<-, _, [assign, value]}) -> + continue, {:<-, _, [assign, value]} -> quote do import Witchcraft.Chain, only: [>>>: 2] - unquote(value) >>> (fn unquote(assign) -> unquote(continue) end) + unquote(value) >>> fn unquote(assign) -> unquote(continue) end end - (continue, value) -> + continue, value -> quote do import Witchcraft.Chain, only: [>>>: 2] unquote(value) >>> fn _ -> unquote(continue) end @@ -444,7 +444,7 @@ defclass Witchcraft.Chain do f = fn x -> Witchcraft.Applicative.of(a, inspect(x)) end g = fn y -> Witchcraft.Applicative.of(a, y <> y) end - left = (a |> Chain.chain(f)) |> Chain.chain(g) + left = a |> Chain.chain(f) |> Chain.chain(g) right = a |> Chain.chain(fn x -> x |> f.() |> Chain.chain(g) end) equal?(left, right) @@ -457,7 +457,7 @@ definst Witchcraft.Chain, for: Function do use Quark @spec chain(Chain.t(), (any() -> any())) :: Chain.t() - def chain(fun, chain_fun), do: fn(r) -> curry(chain_fun).(fun.(r)).(r) end + def chain(fun, chain_fun), do: fn r -> curry(chain_fun).(fun.(r)).(r) end end definst Witchcraft.Chain, for: List do diff --git a/lib/witchcraft/comonad.ex b/lib/witchcraft/comonad.ex index 05e42bd..1320bcc 100644 --- a/lib/witchcraft/comonad.ex +++ b/lib/witchcraft/comonad.ex @@ -29,7 +29,7 @@ defclass Witchcraft.Comonad do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Extend, unquote(opts) + use Witchcraft.Extend, unquote(opts) import unquote(__MODULE__), unquote(opts) end end diff --git a/lib/witchcraft/extend.ex b/lib/witchcraft/extend.ex index bb9c311..ddaf1bf 100644 --- a/lib/witchcraft/extend.ex +++ b/lib/witchcraft/extend.ex @@ -34,7 +34,7 @@ defclass Witchcraft.Extend do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Functor, unquote(opts) + use Witchcraft.Functor, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -85,8 +85,8 @@ defclass Witchcraft.Extend do else a = generate(data) - f = fn x -> "#{inspect x}-#{inspect x}" end - g = fn y -> "#{inspect y} / #{inspect y} / #{inspect y}" end + f = fn x -> "#{inspect(x)}-#{inspect(x)}" end + g = fn y -> "#{inspect(y)} / #{inspect(y)} / #{inspect(y)}" end left = a @@ -144,7 +144,7 @@ defclass Witchcraft.Extend do arg1 = generate(monoid) arg2 = generate(monoid) - left = Witchcraft.Extend.extend(fun, &Quark.id/1) + left = Witchcraft.Extend.extend(fun, &Quark.id/1) right = Witchcraft.Extend.nest(fun) equal?(left.(arg1).(arg2), right.(arg1).(arg2)) @@ -328,7 +328,8 @@ end definst Witchcraft.Extend, for: List do def nest([]), do: [] - def nest(entire = [_head | tail]), do: [entire | nest(tail)] # Could be improved + # Could be improved + def nest(entire = [_head | tail]), do: [entire | nest(tail)] end definst Witchcraft.Extend, for: Tuple do diff --git a/lib/witchcraft/foldable.ex b/lib/witchcraft/foldable.ex index f4d7368..171960a 100644 --- a/lib/witchcraft/foldable.ex +++ b/lib/witchcraft/foldable.ex @@ -49,17 +49,17 @@ defclass Witchcraft.Foldable do if Access.get(opts, :override_kernel, true) do quote do use Witchcraft.Semigroup, unquote(opts) - use Witchcraft.Ord, unquote(opts) + use Witchcraft.Ord, unquote(opts) - import Kernel, unquote(new_opts) - import unquote(__MODULE__), unquote(opts) + import Kernel, unquote(new_opts) + import unquote(__MODULE__), unquote(opts) end else quote do use Witchcraft.Semigroup, unquote(opts) - use Witchcraft.Ord, unquote(opts) + use Witchcraft.Ord, unquote(opts) - import unquote(__MODULE__), unquote(new_opts) + import unquote(__MODULE__), unquote(new_opts) end end end @@ -82,7 +82,7 @@ defclass Witchcraft.Foldable do 15 """ - @spec right_fold(Foldable.t(), any(), ((any(), any()) -> any())) :: any() + @spec right_fold(Foldable.t(), any(), (any(), any() -> any())) :: any() def right_fold(foldable, seed, folder) end @@ -90,7 +90,7 @@ defclass Witchcraft.Foldable do # Free theorm def naturality(data) do foldable = generate(data) - seed = "seed" + seed = "seed" f = &Quark.constant/2 g = &Quark.id/1 @@ -103,7 +103,7 @@ defclass Witchcraft.Foldable do right = foldable |> g.() - |> Witchcraft.Foldable.right_fold(seed, fn(x, acc) -> f.((g.(x)), acc) end) + |> Witchcraft.Foldable.right_fold(seed, fn x, acc -> f.(g.(x), acc) end) equal?(left, right) end @@ -127,7 +127,7 @@ defclass Witchcraft.Foldable do @spec right_fold(Foldable.t(), fun()) :: any() def right_fold(foldable, folder) do case to_list(foldable) do - [] -> [] + [] -> [] [a | as] -> right_fold(as, a, folder) end end @@ -165,10 +165,10 @@ defclass Witchcraft.Foldable do [[[[] | 1] | 2] | 3] """ - @spec left_fold(Foldable.t(), any(), ((any(), any()) -> any())) :: any() + @spec left_fold(Foldable.t(), any(), (any(), any() -> any())) :: any() def left_fold(foldable, seed, folder) do - right_fold(foldable, &Quark.id/1, fn(b, g) -> - fn(x) -> + right_fold(foldable, &Quark.id/1, fn b, g -> + fn x -> x |> folder.(b) |> g.() @@ -199,7 +199,7 @@ defclass Witchcraft.Foldable do 0.5 """ - @spec left_fold(Foldable.t(), ((any(), any()) -> any())) :: any() + @spec left_fold(Foldable.t(), (any(), any() -> any())) :: any() def left_fold(foldable, folder) do [x | xs] = to_list(foldable) left_fold(xs, x, folder) @@ -238,7 +238,7 @@ defclass Witchcraft.Foldable do """ @spec fold_map(Foldable.t(), fun()) :: any() def fold_map(foldable, fun) do - right_fold(foldable, Monoid.empty(foldable), fn(element, acc) -> + right_fold(foldable, Monoid.empty(foldable), fn element, acc -> element |> fun.() |> Semigroup.append(acc) @@ -258,10 +258,10 @@ defclass Witchcraft.Foldable do """ @spec to_list(Foldable.t()) :: [any()] - def to_list(list) when is_list(list), do: list - def to_list(tuple) when is_tuple(tuple), do: Tuple.to_list(tuple) + def to_list(list) when is_list(list), do: list + def to_list(tuple) when is_tuple(tuple), do: Tuple.to_list(tuple) def to_list(string) when is_bitstring(string), do: String.to_charlist(string) - def to_list(foldable), do: right_fold(foldable, [], fn(x, acc) -> [x | acc] end) + def to_list(foldable), do: right_fold(foldable, [], fn x, acc -> [x | acc] end) @doc """ Check if a foldable data structure is empty @@ -279,7 +279,7 @@ defclass Witchcraft.Foldable do """ @spec empty?(Foldable.t()) :: boolean - def empty?(foldable), do: right_fold(foldable, true, fn(_focus, _acc) -> false end) + def empty?(foldable), do: right_fold(foldable, true, fn _focus, _acc -> false end) @doc """ Count the number of elements in a foldable structure @@ -297,10 +297,10 @@ defclass Witchcraft.Foldable do """ @spec length(Foldable.t()) :: non_neg_integer() def length(list) when is_list(list), do: Kernel.length(list) - def length(foldable), do: right_fold(foldable, 0, fn(_, acc) -> 1 + acc end) + def length(foldable), do: right_fold(foldable, 0, fn _, acc -> 1 + acc end) defalias count(foldable), as: :length - defalias size(foldable), as: :length + defalias size(foldable), as: :length @doc """ Check if a foldable structure contains a particular element @@ -322,7 +322,7 @@ defclass Witchcraft.Foldable do """ @spec member?(Foldable.t(), any()) :: boolean() def member?(list, target) when is_list(list), do: Enum.member?(list, target) - def member?(map, target) when is_map(map), do: map |> Map.values() |> Enum.member?(target) + def member?(map, target) when is_map(map), do: map |> Map.values() |> Enum.member?(target) def member?(tuple, target) when is_tuple(tuple) do tuple @@ -337,7 +337,7 @@ defclass Witchcraft.Foldable do end def member?(foldable, target) do - right_fold(foldable, false, fn(focus, acc) -> acc or (focus == target) end) + right_fold(foldable, false, fn focus, acc -> acc or focus == target end) end @doc """ @@ -359,9 +359,9 @@ defclass Witchcraft.Foldable do 2 """ - @spec max(Foldable.t(), by: ((any, any) -> Order.ordering())) :: Ord.t() + @spec max(Foldable.t(), by: (any, any -> Order.ordering())) :: Ord.t() def max(foldable, by: comparator) do - Witchcraft.Foldable.right_fold(foldable, fn(focus, acc) -> + Witchcraft.Foldable.right_fold(foldable, fn focus, acc -> case comparator.(focus, acc) do :greater -> focus _ -> acc @@ -417,9 +417,9 @@ defclass Witchcraft.Foldable do 8 """ - @spec min(Foldable.t(), by: ((any(), any()) -> Order.t())) :: any() | Maybe.t() + @spec min(Foldable.t(), by: (any(), any() -> Order.t())) :: any() | Maybe.t() def min(foldable, by: comparitor) do - right_fold(foldable, fn(focus, acc) -> + right_fold(foldable, fn focus, acc -> case comparitor.(focus, acc) do :lesser -> focus _ -> acc @@ -476,9 +476,9 @@ defclass Witchcraft.Foldable do |> to_list |> safe(&Enum.random/1).() |> case do - %Enum.EmptyError{} -> Foldable.EmptyError.new(foldable) - value -> value - end + %Enum.EmptyError{} -> Foldable.EmptyError.new(foldable) + value -> value + end end @doc ~S""" @@ -583,7 +583,7 @@ defclass Witchcraft.Foldable do @spec flat_map(Foldable.t(), (any() -> [any()])) :: [any()] def flat_map(foldable, mapper) do foldable - |> right_fold([], fn(inner_focus, acc) -> + |> right_fold([], fn inner_focus, acc -> [mapper.(inner_focus) | acc] end) |> flatten() @@ -604,7 +604,7 @@ defclass Witchcraft.Foldable do """ @spec null?(Foldable.t()) :: boolean() - def null?(foldable), do: right_fold(foldable, true, fn(_, _) -> false end) + def null?(foldable), do: right_fold(foldable, true, fn _, _ -> false end) @doc ~S""" Check if a foldable is full of only `true`s @@ -652,7 +652,7 @@ defclass Witchcraft.Foldable do """ @spec all?(Foldable.t(), (any() -> boolean())) :: boolean() def all?(foldable, predicate) do - right_fold(foldable, true, fn(focus, acc) -> predicate.(focus) and acc end) + right_fold(foldable, true, fn focus, acc -> predicate.(focus) and acc end) end @doc ~S""" @@ -706,7 +706,7 @@ defclass Witchcraft.Foldable do """ @spec any?(Foldable.t(), (any() -> boolean())) :: boolean() def any?(foldable, predicate) do - right_fold(foldable, false, fn(focus, acc) -> predicate.(focus) or acc end) + right_fold(foldable, false, fn focus, acc -> predicate.(focus) or acc end) end @doc """ @@ -779,7 +779,7 @@ defclass Witchcraft.Foldable do """ @spec then_traverse(Foldable.t(), Apply.fun()) :: Apply.t() def then_traverse(foldable, fun) do - right_fold(foldable, of(foldable, %Unit{}), fn(step, acc) -> + right_fold(foldable, of(foldable, %Unit{}), fn step, acc -> step |> fun.() |> then(acc) @@ -811,5 +811,4 @@ defclass Witchcraft.Foldable do """ @spec then_traverse(Apply.fun(), Foldable.t()) :: Apply.t() def then_through(fun, traversable), do: then_traverse(traversable, fun) - end diff --git a/lib/witchcraft/foldable/empty_error.ex b/lib/witchcraft/foldable/empty_error.ex index 5ee1da3..0db9133 100644 --- a/lib/witchcraft/foldable/empty_error.ex +++ b/lib/witchcraft/foldable/empty_error.ex @@ -15,10 +15,10 @@ defmodule Witchcraft.Foldable.EmptyError do alias __MODULE__ @type t :: %EmptyError{ - message: String.t(), - data: any(), - plug_status: pos_integer() - } + message: String.t(), + data: any(), + plug_status: pos_integer() + } @base_message "Unable to process empty data" @@ -29,7 +29,7 @@ defmodule Witchcraft.Foldable.EmptyError do case __ENV__.function do {fun_name, arity} -> %EmptyError{ - data: unquote(data), + data: unquote(data), message: "Unable to process empty data in #{__MODULE__}.#{fun_name}/#{arity}" } diff --git a/lib/witchcraft/functor.ex b/lib/witchcraft/functor.ex index f0bb514..e3425e6 100644 --- a/lib/witchcraft/functor.ex +++ b/lib/witchcraft/functor.ex @@ -67,7 +67,7 @@ defclass Witchcraft.Functor do f = fn x -> inspect(wrapped == x) end g = fn x -> inspect(wrapped != x) end - left = Functor.map(wrapped, fn x -> x |> g.() |> f.() end) + left = Functor.map(wrapped, fn x -> x |> g.() |> f.() end) right = wrapped |> Functor.map(g) |> Functor.map(f) equal?(left, right) @@ -182,7 +182,7 @@ defclass Witchcraft.Functor do """ @spec replace(Functor.t(), any()) :: Functor.t() - def replace(wrapped, replace_with), do: wrapped ~> &constant(replace_with, &1) + def replace(wrapped, replace_with), do: wrapped ~> (&constant(replace_with, &1)) @doc """ `map` a function over a data structure, with each mapping occuring asynchronously. @@ -206,7 +206,7 @@ defclass Witchcraft.Functor do @spec async_map(Functor.t(), (any() -> any())) :: Functor.t() def async_map(functor, fun) do functor - |> Functor.map(fn(item) -> + |> Functor.map(fn item -> Task.async(fn -> fun.(item) end) diff --git a/lib/witchcraft/monad.ex b/lib/witchcraft/monad.ex index fb476a6..9e9476c 100644 --- a/lib/witchcraft/monad.ex +++ b/lib/witchcraft/monad.ex @@ -45,7 +45,7 @@ defclass Witchcraft.Monad do defmacro __using__(opts \\ []) do quote do use Witchcraft.Applicative, unquote(opts) - use Witchcraft.Chain, unquote(opts) + use Witchcraft.Chain, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -58,7 +58,7 @@ defclass Witchcraft.Monad do a = generate(data) f = &Witchcraft.Functor.replace(a, inspect(&1)) - left = a |> of(a) |> chain(f) + left = a |> of(a) |> chain(f) right = f.(a) equal?(left, right) @@ -66,7 +66,7 @@ defclass Witchcraft.Monad do def right_identity(data) do a = generate(data) - left = a >>> &of(a, &1) + left = a >>> (&of(a, &1)) equal?(a, left) end diff --git a/lib/witchcraft/monoid.ex b/lib/witchcraft/monoid.ex index 69f44b8..32f30bd 100644 --- a/lib/witchcraft/monoid.ex +++ b/lib/witchcraft/monoid.ex @@ -21,7 +21,7 @@ defclass Witchcraft.Monoid do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Semigroup, unquote(opts) + use Witchcraft.Semigroup, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -56,7 +56,7 @@ defclass Witchcraft.Monoid do false """ - @spec empty?(Monoid.t) :: boolean + @spec empty?(Monoid.t()) :: boolean def empty?(monoid), do: empty(monoid) == monoid properties do diff --git a/lib/witchcraft/ord.ex b/lib/witchcraft/ord.ex index 72bc2e2..c259e8b 100644 --- a/lib/witchcraft/ord.ex +++ b/lib/witchcraft/ord.ex @@ -33,14 +33,14 @@ defclass Witchcraft.Ord do if Access.get(opts, :override_kernel, true) do quote do - import Kernel, unquote(new_opts) + import Kernel, unquote(new_opts) use Witchcraft.Semigroupoid, unquote(opts) - import unquote(__MODULE__), unquote(opts) + import unquote(__MODULE__), unquote(opts) end else quote do use Witchcraft.Semigroupoid, unquote(opts) - import unquote(__MODULE__), unquote(new_opts) + import unquote(__MODULE__), unquote(new_opts) end end end @@ -134,7 +134,7 @@ defclass Witchcraft.Ord do @spec greater?(Ord.t(), Ord.t()) :: boolean() def greater?(a, b), do: compare(a, b) == :greater - defalias a > b, [as: :greater?] + defalias a > b, as: :greater? @doc """ Determine if an element is `:lesser` than another @@ -151,7 +151,7 @@ defclass Witchcraft.Ord do @spec lesser?(Ord.t(), Ord.t()) :: boolean() def lesser?(a, b), do: compare(a, b) == :lesser - defalias a < b, [as: :lesser?] + defalias a < b, as: :lesser? @doc """ Determine if an element is `:lesser` or `:equal` to another diff --git a/lib/witchcraft/ord/bitstring.ex b/lib/witchcraft/ord/bitstring.ex index 007db22..f2051a9 100644 --- a/lib/witchcraft/ord/bitstring.ex +++ b/lib/witchcraft/ord/bitstring.ex @@ -4,8 +4,8 @@ definst Witchcraft.Ord, for: BitString do def compare(string_a, string_b) do cond do string_a == string_b -> :equal - string_a < string_b -> :lesser - true -> :greater + string_a < string_b -> :lesser + true -> :greater end end end diff --git a/lib/witchcraft/ord/float.ex b/lib/witchcraft/ord/float.ex index 21c110c..b9e0fc9 100644 --- a/lib/witchcraft/ord/float.ex +++ b/lib/witchcraft/ord/float.ex @@ -2,6 +2,6 @@ import TypeClass definst Witchcraft.Ord, for: Float do def compare(float_a, float_b) when float_a == float_b, do: :equal - def compare(float_a, float_b) when float_a > float_b, do: :greater - def compare(float_a, float_b) when float_a < float_b, do: :lesser + def compare(float_a, float_b) when float_a > float_b, do: :greater + def compare(float_a, float_b) when float_a < float_b, do: :lesser end diff --git a/lib/witchcraft/ord/integer.ex b/lib/witchcraft/ord/integer.ex index 68b10c9..529f46b 100644 --- a/lib/witchcraft/ord/integer.ex +++ b/lib/witchcraft/ord/integer.ex @@ -2,6 +2,6 @@ import TypeClass definst Witchcraft.Ord, for: Integer do def compare(int_a, int_b) when int_a == int_b, do: :equal - def compare(int_a, int_b) when int_a > int_b, do: :greater - def compare(int_a, int_b) when int_a < int_b, do: :lesser + def compare(int_a, int_b) when int_a > int_b, do: :greater + def compare(int_a, int_b) when int_a < int_b, do: :lesser end diff --git a/lib/witchcraft/ord/list.ex b/lib/witchcraft/ord/list.ex index 905bec5..573b15f 100644 --- a/lib/witchcraft/ord/list.ex +++ b/lib/witchcraft/ord/list.ex @@ -15,8 +15,8 @@ definst Witchcraft.Ord, for: List do def compare(list_a, list_b) do cond do list_a == list_b -> :equal - list_a < list_b -> :lesser - true -> :greater + list_a < list_b -> :lesser + true -> :greater end end end diff --git a/lib/witchcraft/semigroup.ex b/lib/witchcraft/semigroup.ex index e2a78f1..b92708a 100644 --- a/lib/witchcraft/semigroup.ex +++ b/lib/witchcraft/semigroup.ex @@ -34,11 +34,11 @@ defclass Witchcraft.Semigroup do if Access.get(opts, :override_kernel, true) do quote do - import Kernel, unquote(new_opts) + import Kernel, unquote(new_opts) import unquote(__MODULE__), unquote(opts) end else - quote do: import unquote(__MODULE__), unquote(new_opts) + quote do: import(unquote(__MODULE__), unquote(new_opts)) end end @@ -109,7 +109,7 @@ defclass Witchcraft.Semigroup do [1, 2, 3, 1, 2, 3, 1, 2, 3] """ - @spec repeat(Semigroup.t(), [times: non_neg_integer()]) :: Semigroup.t() + @spec repeat(Semigroup.t(), times: non_neg_integer()) :: Semigroup.t() # credo:disable-for-lines:6 Credo.Check.Refactor.PipeChainStart def repeat(to_repeat, times: times) do fn -> to_repeat end @@ -124,7 +124,7 @@ defclass Witchcraft.Semigroup do b = generate(data) c = generate(data) - left = a |> Semigroup.append(b) |> Semigroup.append(c) + left = a |> Semigroup.append(b) |> Semigroup.append(c) right = Semigroup.append(a, Semigroup.append(b, c)) equal?(left, right) @@ -176,7 +176,7 @@ definst Witchcraft.Semigroup, for: Tuple do tuple_a |> Tuple.to_list() |> Enum.zip(Tuple.to_list(tuple_b)) - |> Enum.map(fn({x, y}) -> Witchcraft.Semigroup.append(x, y) end) + |> Enum.map(fn {x, y} -> Witchcraft.Semigroup.append(x, y) end) |> List.to_tuple() end end diff --git a/lib/witchcraft/semigroupoid.ex b/lib/witchcraft/semigroupoid.ex index e6633f5..aac0d8a 100644 --- a/lib/witchcraft/semigroupoid.ex +++ b/lib/witchcraft/semigroupoid.ex @@ -25,11 +25,11 @@ defclass Witchcraft.Semigroupoid do if Access.get(opts, :override_kernel, true) do quote do - import Kernel, unquote(new_opts) + import Kernel, unquote(new_opts) import unquote(__MODULE__), unquote(opts) end else - quote do: import unquote(__MODULE__), unquote(new_opts) + quote do: import(unquote(__MODULE__), unquote(new_opts)) end end @@ -131,7 +131,7 @@ defclass Witchcraft.Semigroupoid do b = generate(data) c = generate(data) - left = Semigroupoid.compose(Semigroupoid.compose(a, b), c) + left = Semigroupoid.compose(Semigroupoid.compose(a, b), c) right = Semigroupoid.compose(a, Semigroupoid.compose(b, c)) equal?(left, right) diff --git a/lib/witchcraft/setoid.ex b/lib/witchcraft/setoid.ex index bc044c2..6b4596d 100644 --- a/lib/witchcraft/setoid.ex +++ b/lib/witchcraft/setoid.ex @@ -28,11 +28,11 @@ defclass Witchcraft.Setoid do if Access.get(opts, :override_kernel, true) do quote do - import Kernel, unquote(new_opts) + import Kernel, unquote(new_opts) import unquote(__MODULE__), unquote(opts) end else - quote do: import unquote(__MODULE__), unquote(new_opts) + quote do: import(unquote(__MODULE__), unquote(new_opts)) end end @@ -71,7 +71,7 @@ defclass Witchcraft.Setoid do def equivalent?(a, b) end - defalias a == b, [as: :equivalent?] + defalias a == b, as: :equivalent? @doc """ The opposite of `equivalent?/2` @@ -85,7 +85,7 @@ defclass Witchcraft.Setoid do @spec nonequivalent?(Setoid.t(), Setoid.t()) :: boolean() def nonequivalent?(a, b), do: not equivalent?(a, b) - defalias a != b, [as: :nonequivalent?] + defalias a != b, as: :nonequivalent? properties do def reflexivity(data) do diff --git a/lib/witchcraft/traversable.ex b/lib/witchcraft/traversable.ex index b1a1c42..00e203a 100644 --- a/lib/witchcraft/traversable.ex +++ b/lib/witchcraft/traversable.ex @@ -35,8 +35,8 @@ defclass Witchcraft.Traversable do defmacro __using__(opts \\ []) do quote do - use Witchcraft.Foldable, unquote(opts) - use Witchcraft.Functor, unquote(opts) + use Witchcraft.Foldable, unquote(opts) + use Witchcraft.Functor, unquote(opts) import unquote(__MODULE__), unquote(opts) end end @@ -238,11 +238,11 @@ definst Witchcraft.Traversable, for: List do use Witchcraft.Foldable def traverse([], link), do: of(link.([]), []) - def traverse(list = [head | _], link) do - right_fold(list, of(link.(head), []), fn(x, acc) -> + def traverse(list = [head | _], link) do + right_fold(list, of(link.(head), []), fn x, acc -> # credo:disable-for-lines:2 Credo.Check.Refactor.PipeChainStart - fn(link_head, link_tail) -> [link_head | link_tail] end + fn link_head, link_tail -> [link_head | link_tail] end |> over(link.(x), acc) end) end diff --git a/mix.exs b/mix.exs index 605f735..6ae346c 100644 --- a/mix.exs +++ b/mix.exs @@ -3,40 +3,31 @@ defmodule Witchcraft.Mixfile do def project do [ - app: :witchcraft, + app: :witchcraft, name: "Witchcraft", description: "Monads and other dark magic (monoids, functors, traversables, &c)", - - version: "1.0.0", - elixir: "~> 1.5", - + version: "1.0.1", + elixir: "~> 1.5", package: [ maintainers: ["Brooklyn Zelenka"], - licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/expede/witchcraft"} + licenses: ["MIT"], + links: %{"GitHub" => "https://github.com/expede/witchcraft"} ], - - source_url: "https://github.com/expede/witchcraft", + source_url: "https://github.com/expede/witchcraft", homepage_url: "https://github.com/expede/witchcraft", - - aliases: ["quality": ["test", "credo --strict", "inch"]], - + aliases: [quality: ["test", "credo --strict", "inch"]], deps: [ - {:inch_ex, "~> 0.5", only: [:dev, :docs, :test]}, - - {:credo, "~> 0.8", only: [:dev, :test]}, + {:inch_ex, "~> 0.5", only: [:dev, :docs, :test]}, + {:credo, "~> 0.8", only: [:dev, :test]}, {:benchfella, "~> 0.3", only: [:dev, :test]}, - - {:dialyxir, "~> 0.3", only: :dev}, - {:earmark, "~> 1.2", only: :dev}, - {:ex_doc, "~> 0.15", only: :dev}, - + {:dialyxir, "~> 0.3", only: :dev}, + {:earmark, "~> 1.2", only: :dev}, + {:ex_doc, "~> 0.15", only: :dev}, {:exceptional, "~> 2.1"}, - {:operator, "~> 0.2"}, - {:quark, "~> 2.2"}, - {:type_class, "~> 1.2"} + {:operator, "~> 0.2"}, + {:quark, "~> 2.2"}, + {:type_class, "~> 1.2"} ], - docs: [ extras: ["README.md"], logo: "./brand/Icon/PNG/WC-icon-sml@2x-circle.png", diff --git a/mix.lock b/mix.lock index f1403d7..5a63ac4 100644 --- a/mix.lock +++ b/mix.lock @@ -1,14 +1,14 @@ -%{"algae": {:hex, :algae, "0.12.1", "79ef7ed521fc6bf3dd2401002f04b06003db487c5c261aa6cc54835e25768a3d", [:mix], [{:quark, "~> 2.2", [hex: :quark, repo: "hexpm", optional: false]}], "hexpm"}, - "benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [], [], "hexpm"}, - "bmark": {:hex, :bmark, "1.0.3", "516e4383fbf6128b580925336ae2ccda50ecb68ce393d72a04b152165ce87df4", [], [], "hexpm"}, +%{ + "benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [:mix], [], "hexpm"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, - "credo": {:hex, :credo, "0.8.4", "4e50acac058cf6292d6066e5b0d03da5e1483702e1ccde39abba385c9f03ead4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"}, + "credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.16.2", "3b3e210ebcd85a7c76b4e73f85c5640c011d2a0b2f06dcdf5acdb2ae904e5084", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, + "earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "exceptional": {:hex, :exceptional, "2.1.0", "b3bc6c7041a242df9f7e18223649f3d66633827897138cf5f26c46c88b6925ae", [:mix], [], "hexpm"}, "inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "operator": {:hex, :operator, "0.2.0", "b613bdb520a20dbc016d921d444fd2ef2212136be9385d6dca448a2a38d0577f", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "quark": {:hex, :quark, "2.3.0", "3742ddc14441b4930c7067741879cb5b3e4881f391ea0aed7b138f20d16b30bb", [:mix], [], "hexpm"}, - "type_class": {:hex, :type_class, "1.2.2", "a84cab53b80e7c3c15f5ba9a550f5c68646c2b965d19f711f37473803d1ec2ff", [:mix], [{:exceptional, "~> 2.1", [hex: :exceptional, repo: "hexpm", optional: false]}], "hexpm"}} + "type_class": {:hex, :type_class, "1.2.4", "2049a5606c7ca215347cb1488db5c5306665dc166be3fdea111c42adb447f382", [:mix], [{:exceptional, "~> 2.1", [hex: :exceptional, repo: "hexpm", optional: false]}], "hexpm"}, +} diff --git a/test/do_notation_test.exs b/test/do_notation_test.exs index afb1594..3987bd0 100644 --- a/test/do_notation_test.exs +++ b/test/do_notation_test.exs @@ -48,7 +48,7 @@ defmodule Witchcraft.DoNotationTest do a <- [1, 2, 3] [a] [a] - end + end assert done == [1, 2, 3] end @@ -124,33 +124,105 @@ defmodule Witchcraft.DoNotationTest do let tens = c * 10 d <- [c - 1, c + 1] [a, b, c, d] - end + end assert done == [ - 1, 3, 1, 0, - 1, 3, 1, 2, - 1, 3, 3, 2, - 1, 3, 3, 4, - 1, 3, 3, 2, - 1, 3, 3, 4, - 1, 4, 1, 0, - 1, 4, 1, 2, - 1, 4, 4, 3, - 1, 4, 4, 5, - 1, 4, 4, 3, - 1, 4, 4, 5, - 2, 3, 2, 1, - 2, 3, 2, 3, - 2, 3, 3, 2, - 2, 3, 3, 4, - 2, 3, 6, 5, - 2, 3, 6, 7, - 2, 4, 2, 1, - 2, 4, 2, 3, - 2, 4, 4, 3, - 2, 4, 4, 5, - 2, 4, 8, 7, - 2, 4, 8, 9 - ] + 1, + 3, + 1, + 0, + 1, + 3, + 1, + 2, + 1, + 3, + 3, + 2, + 1, + 3, + 3, + 4, + 1, + 3, + 3, + 2, + 1, + 3, + 3, + 4, + 1, + 4, + 1, + 0, + 1, + 4, + 1, + 2, + 1, + 4, + 4, + 3, + 1, + 4, + 4, + 5, + 1, + 4, + 4, + 3, + 1, + 4, + 4, + 5, + 2, + 3, + 2, + 1, + 2, + 3, + 2, + 3, + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 4, + 2, + 3, + 6, + 5, + 2, + 3, + 6, + 7, + 2, + 4, + 2, + 1, + 2, + 4, + 2, + 3, + 2, + 4, + 4, + 3, + 2, + 4, + 4, + 5, + 2, + 4, + 8, + 7, + 2, + 4, + 8, + 9 + ] end end diff --git a/test/witchcraft_test.exs b/test/witchcraft_test.exs index f1ac89d..f879b37 100644 --- a/test/witchcraft_test.exs +++ b/test/witchcraft_test.exs @@ -18,26 +18,26 @@ defmodule WitchcraftTest do ################ doctest Witchcraft.Semigroupoid, import: true - doctest Witchcraft.Category, import: true - doctest Witchcraft.Arrow, import: true + doctest Witchcraft.Category, import: true + doctest Witchcraft.Arrow, import: true doctest Witchcraft.Setoid, import: true - doctest Witchcraft.Ord, import: true + doctest Witchcraft.Ord, import: true doctest Witchcraft.Semigroup, import: true - doctest Witchcraft.Monoid, import: true + doctest Witchcraft.Monoid, import: true - doctest Witchcraft.Foldable, import: true + doctest Witchcraft.Foldable, import: true doctest Witchcraft.Traversable, import: true - doctest Witchcraft.Functor, import: true + doctest Witchcraft.Functor, import: true doctest Witchcraft.Bifunctor, import: true - doctest Witchcraft.Extend, import: true + doctest Witchcraft.Extend, import: true doctest Witchcraft.Comonad, import: true - doctest Witchcraft.Apply, import: true + doctest Witchcraft.Apply, import: true doctest Witchcraft.Applicative, import: true - doctest Witchcraft.Chain, import: true - doctest Witchcraft.Monad, import: true + doctest Witchcraft.Chain, import: true + doctest Witchcraft.Monad, import: true end