diff options
Diffstat (limited to 'gen')
-rw-r--r-- | gen/src/gleam@function.erl | 5 | ||||
-rw-r--r-- | gen/test/gleam@function_test.erl | 23 |
2 files changed, 19 insertions, 9 deletions
diff --git a/gen/src/gleam@function.erl b/gen/src/gleam@function.erl index f014d37..b376ed0 100644 --- a/gen/src/gleam@function.erl +++ b/gen/src/gleam@function.erl @@ -1,10 +1,13 @@ -module(gleam@function). -compile(no_auto_import). --export([compose/2, flip/1]). +-export([compose/2, flip/1, identity/1]). compose(Fun1, Fun2) -> fun(A) -> Fun2(Fun1(A)) end. flip(Fun) -> fun(B, A) -> Fun(A, B) end. + +identity(X) -> + X. diff --git a/gen/test/gleam@function_test.erl b/gen/test/gleam@function_test.erl index 47758c5..58f6a57 100644 --- a/gen/test/gleam@function_test.erl +++ b/gen/test/gleam@function_test.erl @@ -1,7 +1,7 @@ -module(gleam@function_test). -compile(no_auto_import). --export([compose_test/0, flip_test/0]). +-export([compose_test/0, flip_test/0, identity_test/0]). compose_test() -> AddTwo = fun(Int) -> Int + 2 end, @@ -9,23 +9,24 @@ compose_test() -> AddFive = gleam@function:compose(AddTwo, AddThree), gleam@expect:equal(AddFive(1), 6), HeadToString = gleam@function:compose( - fun gleam@list:head/1, - fun(IntResult) -> - gleam@int:to_string(gleam@result:unwrap(IntResult, 0)) - end + gleam@function:compose( + fun gleam@list:head/1, + fun(Capture1) -> gleam@result:unwrap(Capture1, 0) end + ), + fun gleam@int:to_string/1 ), gleam@expect:equal(HeadToString([1]), <<"1">>), gleam@expect:equal(HeadToString([]), <<"0">>). flip_test() -> - Fun = fun(String, Int) -> + Fun = fun(S, I) -> gleam@string:append( gleam@string:append( gleam@string:append( - gleam@string:append(<<"String: '">>, String), + gleam@string:append(<<"String: '">>, S), <<"', Int: '">> ), - gleam@int:to_string(Int) + gleam@int:to_string(I) ), <<"'">> ) @@ -36,3 +37,9 @@ flip_test() -> FlippedFun(2, <<"Alice">>), <<"String: 'Alice', Int: '2'">> ). + +identity_test() -> + gleam@expect:equal(gleam@function:identity(1), 1), + gleam@expect:equal(gleam@function:identity(<<"">>), <<"">>), + gleam@expect:equal(gleam@function:identity([]), []), + gleam@expect:equal(gleam@function:identity({1, 2.0}), {1, 2.0}). |