witchcrafters / witchcraft

Monads and other dark magic for Elixir
https://witchcrafters.github.io
MIT License
1.2k stars 58 forks source link

`Witchcraft.Chain.do_notation/2` intentionally ignores `chainer` #108

Open florius0 opened 2 years ago

florius0 commented 2 years ago

As far as I see, there are multiple places where second argument of chainer is used: https://github.com/witchcrafters/witchcraft/blob/73e3cc6aee1a06e738a33c2aa8736ac19907ff96/lib/witchcraft/chain.ex#L410-L431

Instead >>> (Witchcraft.Chain.chain) is used.

Is it designed to be so, or it is a typo?

PS IMO it should be

def do_notation(input, chainer) do
  input
  |> normalize()
  |> Enum.reverse()
  |> Witchcraft.Foldable.left_fold(fn
    continue, {:let, _, [{:=, _, [assign, value]}]} ->
      quote do: unquote(value) |> (fn unquote(assign) -> unquote(continue) end).()

    continue, {:<-, _, [assign, value]} ->
      quote do
        apply(unquote(chainer), [unquote(value), fn unquote(assign) -> unquote(continue) end])
      end

    continue, value ->
      quote do
        apply(unquote(chainer), [unquote(value), fn _ -> unquote(continue) end])
      end
  end)
end