From 2e8b6d5f2bcf5c1c9c8d85f389cb6660fd72a28e Mon Sep 17 00:00:00 2001 From: Vadim Tsvetkov Date: Wed, 22 Jun 2022 22:43:33 +0300 Subject: [PATCH 1/2] Improve zero arity tests --- test/quark/curry_test.exs | 8 ++++++++ test/quark/partial_test.exs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/test/quark/curry_test.exs b/test/quark/curry_test.exs index 5d2b108..9119e9c 100644 --- a/test/quark/curry_test.exs +++ b/test/quark/curry_test.exs @@ -22,4 +22,12 @@ defmodule Quark.CurryTest do below10 = minus().(10) assert below10.(9) == 1 end + + defcurry one(), do: 1 + defcurry two, do: 2 + + test "supports zero arity" do + assert one() == 1 + assert two == 2 + end end diff --git a/test/quark/partial_test.exs b/test/quark/partial_test.exs index fb18610..022a8d7 100644 --- a/test/quark/partial_test.exs +++ b/test/quark/partial_test.exs @@ -3,8 +3,10 @@ defmodule Quark.PartialTest do import Quark.Partial defpartial one(), do: 1 + defpartial two, do: 2 test "creates zero arity functions" do assert one() == 1 + assert two() == 2 end defpartial minus(a, b, c), do: a - b - c From 78ea4350544ff22ed5495077bb8f12fa7ea2d63a Mon Sep 17 00:00:00 2001 From: Vadim Tsvetkov Date: Wed, 22 Jun 2022 22:46:50 +0300 Subject: [PATCH 2/2] Fix `defpartial` and `defcurry` do not support zero arity functions without parentheses #45 --- lib/quark/curry.ex | 1 + lib/quark/partial.ex | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/quark/curry.ex b/lib/quark/curry.ex index 7efb333..d6eda25 100644 --- a/lib/quark/curry.ex +++ b/lib/quark/curry.ex @@ -100,4 +100,5 @@ defmodule Quark.Curry do end defp wrap([], body), do: body + defp wrap(nil, body), do: body end diff --git a/lib/quark/partial.ex b/lib/quark/partial.ex index d3ca533..3220e7c 100644 --- a/lib/quark/partial.ex +++ b/lib/quark/partial.ex @@ -48,7 +48,11 @@ defmodule Quark.Partial do #=> 3 """ - defmacro defpartial({fun_name, ctx, args}, do: body) do + defmacro defpartial({fun_name, ctx, nil}, do: body), do: defpartial_quote({fun_name, ctx, []}, do: body) + + defmacro defpartial({fun_name, ctx, args}, do: body), do: defpartial_quote({fun_name, ctx, args}, do: body) + + defp defpartial_quote({fun_name, ctx, args}, do: body) do quote do defcurry unquote({fun_name, ctx, args}), do: unquote(body) unquote do: Enum.map(args_scan(args), &rehydrate(fun_name, ctx, &1))