diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-03-15 14:50:11 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-03-15 14:54:02 +0000 |
commit | d613e26ebd67b704ab58c28cc559ee01ae03b547 (patch) | |
tree | 96e484695221b0a39dee2ffc51aa0c0b7249d87e /gen | |
parent | 1ce9a14ba69c593bb40998a5a49d3f066a4aa07a (diff) | |
download | gleam_stdlib-d613e26ebd67b704ab58c28cc559ee01ae03b547.tar.gz gleam_stdlib-d613e26ebd67b704ab58c28cc559ee01ae03b547.zip |
Erase directly called capture funs
Diffstat (limited to 'gen')
-rw-r--r-- | gen/bool.erl | 37 | ||||
-rw-r--r-- | gen/iodata.erl | 15 | ||||
-rw-r--r-- | gen/list.erl | 66 | ||||
-rw-r--r-- | gen/map.erl | 56 | ||||
-rw-r--r-- | gen/order.erl | 66 | ||||
-rw-r--r-- | gen/result.erl | 60 |
6 files changed, 116 insertions, 184 deletions
diff --git a/gen/bool.erl b/gen/bool.erl index 01c81ce..a02edc8 100644 --- a/gen/bool.erl +++ b/gen/bool.erl @@ -2,7 +2,22 @@ -compile(no_auto_import). -include_lib("eunit/include/eunit.hrl"). --export([max/2, min/2, to_int/1]). +-export([negate/1, max/2, min/2, to_int/1]). + +negate(Bool) -> + case Bool of + true -> + false; + + false -> + true + end. + +-ifdef(TEST). +negate_test() -> + expect:false(negate(true)), + expect:true(negate(false)). +-endif. max(A, B) -> case A of @@ -15,10 +30,10 @@ max(A, B) -> -ifdef(TEST). max_test() -> - (fun(Capture1) -> expect:equal(Capture1, true) end)(max(true, true)), - (fun(Capture1) -> expect:equal(Capture1, true) end)(max(true, false)), - (fun(Capture1) -> expect:equal(Capture1, false) end)(max(false, false)), - (fun(Capture1) -> expect:equal(Capture1, true) end)(max(false, true)). + expect:equal(max(true, true), true), + expect:equal(max(true, false), true), + expect:equal(max(false, false), false), + expect:equal(max(false, true), true). -endif. min(A, B) -> @@ -32,10 +47,10 @@ min(A, B) -> -ifdef(TEST). min_test() -> - (fun(Capture1) -> expect:equal(Capture1, true) end)(min(true, true)), - (fun(Capture1) -> expect:equal(Capture1, false) end)(min(true, false)), - (fun(Capture1) -> expect:equal(Capture1, false) end)(min(false, false)), - (fun(Capture1) -> expect:equal(Capture1, false) end)(min(false, true)). + expect:equal(min(true, true), true), + expect:equal(min(true, false), false), + expect:equal(min(false, false), false), + expect:equal(min(false, true), false). -endif. to_int(Bool) -> @@ -49,6 +64,6 @@ to_int(Bool) -> -ifdef(TEST). to_int_test() -> - (fun(Capture1) -> expect:equal(Capture1, 1) end)(to_int(true)), - (fun(Capture1) -> expect:equal(Capture1, 0) end)(to_int(false)). + expect:equal(to_int(true), 1), + expect:equal(to_int(false), 0). -endif. diff --git a/gen/iodata.erl b/gen/iodata.erl index afc2803..5503bf1 100644 --- a/gen/iodata.erl +++ b/gen/iodata.erl @@ -21,15 +21,8 @@ byte_size(A) -> -ifdef(TEST). iodata_test() -> - Iodata = (fun(Capture1) -> - prepend(Capture1, <<"H">>) - end)((fun(Capture1) -> - append(Capture1, <<" world!">>) - end)((fun(Capture1) -> - append(Capture1, <<",">>) - end)(from([<<"ello">>])))), - (fun(Capture1) -> - expect:equal(Capture1, <<"Hello, world!">>) - end)(to_string(Iodata)), - (fun(Capture1) -> expect:equal(Capture1, 13) end)(byte_size(Iodata)). + Iodata = prepend(append(append(from([<<"ello">>]), <<",">>), <<" world!">>), + <<"H">>), + expect:equal(to_string(Iodata), <<"Hello, world!">>), + expect:equal(byte_size(Iodata), 13). -endif. diff --git a/gen/list.erl b/gen/list.erl index 3155824..662b283 100644 --- a/gen/list.erl +++ b/gen/list.erl @@ -9,10 +9,10 @@ length(A) -> -ifdef(TEST). length_test() -> - (fun(Capture1) -> expect:equal(Capture1, 0) end)(length([])), - (fun(Capture1) -> expect:equal(Capture1, 1) end)(length([1])), - (fun(Capture1) -> expect:equal(Capture1, 2) end)(length([1, 1])), - (fun(Capture1) -> expect:equal(Capture1, 3) end)(length([1, 1, 1])). + expect:equal(length([]), 0), + expect:equal(length([1]), 1), + expect:equal(length([1, 1]), 2), + expect:equal(length([1, 1, 1]), 3). -endif. reverse(A) -> @@ -20,8 +20,8 @@ reverse(A) -> -ifdef(TEST). reverse_test() -> - (fun(Capture1) -> expect:equal(Capture1, 0) end)(length([])), - (fun(Capture1) -> expect:equal(Capture1, 5) end)(length([1, 2, 3, 4, 5])). + expect:equal(length([]), 0), + expect:equal(length([1, 2, 3, 4, 5]), 5). -endif. is_empty(List) -> @@ -60,8 +60,8 @@ head(List) -> -ifdef(TEST). head_test() -> - (fun(Capture1) -> expect:equal(Capture1, {ok, 0}) end)(head([0, 4, 5, 7])), - (fun(Capture1) -> expect:equal(Capture1, {error, empty}) end)(head([])). + expect:equal(head([0, 4, 5, 7]), {ok, 0}), + expect:equal(head([]), {error, empty}). -endif. tail(List) -> @@ -75,11 +75,9 @@ tail(List) -> -ifdef(TEST). tail_test() -> - (fun(Capture1) -> - expect:equal(Capture1, {ok, [4, 5, 7]}) - end)(tail([0, 4, 5, 7])), - (fun(Capture1) -> expect:equal(Capture1, {ok, []}) end)(tail([0])), - (fun(Capture1) -> expect:equal(Capture1, {error, empty}) end)(tail([])). + expect:equal(tail([0, 4, 5, 7]), {ok, [4, 5, 7]}), + expect:equal(tail([0]), {ok, []}), + expect:equal(tail([]), {error, empty}). -endif. do_map(List, Fun, Acc) -> @@ -96,14 +94,8 @@ map(List, Fun) -> -ifdef(TEST). map_test() -> - (fun(Capture1) -> - expect:equal(Capture1, []) - end)((fun(Capture1) -> map(Capture1, fun(X) -> X * 2 end) end)([])), - (fun(Capture1) -> - expect:equal(Capture1, [0, 8, 10, 14, 6]) - end)((fun(Capture1) -> - map(Capture1, fun(X) -> X * 2 end) - end)([0, 4, 5, 7, 3])). + expect:equal(map([], fun(X) -> X * 2 end), []), + expect:equal(map([0, 4, 5, 7, 3], fun(X) -> X * 2 end), [0, 8, 10, 14, 6]). -endif. do_traverse(List, Fun, Acc) -> @@ -133,12 +125,8 @@ traverse_test() -> false -> {error, X} end end, - (fun(Capture1) -> - expect:equal(Capture1, {ok, [10, 12, 10, 12]}) - end)((fun(Capture1) -> traverse(Capture1, Fun) end)([5, 6, 5, 6])), - (fun(Capture1) -> - expect:equal(Capture1, {error, 7}) - end)((fun(Capture1) -> traverse(Capture1, Fun) end)([4, 6, 5, 7, 3])). + expect:equal(traverse([5, 6, 5, 6], Fun), {ok, [10, 12, 10, 12]}), + expect:equal(traverse([4, 6, 5, 7, 3], Fun), {error, 7}). -endif. new() -> @@ -146,7 +134,7 @@ new() -> -ifdef(TEST). new_test() -> - (fun(Capture1) -> expect:equal(Capture1, []) end)(new()). + expect:equal(new(), []). -endif. append(A, B) -> @@ -171,12 +159,10 @@ flatten(Lists) -> -ifdef(TEST). flatten_test() -> - (fun(Capture1) -> expect:equal(Capture1, []) end)(flatten([])), - (fun(Capture1) -> expect:equal(Capture1, []) end)(flatten([[]])), - (fun(Capture1) -> expect:equal(Capture1, []) end)(flatten([[], [], []])), - (fun(Capture1) -> - expect:equal(Capture1, [1, 2, 3, 4]) - end)(flatten([[1, 2], [], [3, 4]])). + expect:equal(flatten([]), []), + expect:equal(flatten([[]]), []), + expect:equal(flatten([[], [], []]), []), + expect:equal(flatten([[1, 2], [], [3, 4]]), [1, 2, 3, 4]). -endif. foldl(List, Acc, Fun) -> @@ -190,11 +176,7 @@ foldl(List, Acc, Fun) -> -ifdef(TEST). foldl_test() -> - (fun(Capture1) -> - expect:equal(Capture1, [3, 2, 1]) - end)((fun(Capture1) -> - foldl(Capture1, [], fun(X, Acc) -> [X | Acc] end) - end)([1, 2, 3])). + expect:equal(foldl([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end), [3, 2, 1]). -endif. foldr(List, Acc, Fun) -> @@ -208,9 +190,5 @@ foldr(List, Acc, Fun) -> -ifdef(TEST). foldr_test() -> - (fun(Capture1) -> - expect:equal(Capture1, [1, 2, 3]) - end)((fun(Capture1) -> - foldr(Capture1, [], fun(X, Acc) -> [X | Acc] end) - end)([1, 2, 3])). + expect:equal(foldr([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end), [1, 2, 3]). -endif. diff --git a/gen/map.erl b/gen/map.erl index 7a4bafa..5fffb8a 100644 --- a/gen/map.erl +++ b/gen/map.erl @@ -17,7 +17,7 @@ from_list(A) -> from_list_test() -> Proplist = [{4, 0}, {1, 0}], Map = from_list(Proplist), - (fun(Capture1) -> expect:equal(Capture1, 2) end)(size(Map)). + expect:equal(size(Map), 2). -endif. is_key(A, B) -> @@ -28,16 +28,10 @@ has_key(Map, Key) -> -ifdef(TEST). has_key_test() -> - expect:false((fun(Capture1) -> has_key(Capture1, 1) end)(from_list([]))), - expect:true((fun(Capture1) -> - has_key(Capture1, 1) - end)(from_list([{1, 0}]))), - expect:true((fun(Capture1) -> - has_key(Capture1, 1) - end)(from_list([{4, 0}, {1, 0}]))), - expect:false((fun(Capture1) -> - has_key(Capture1, 0) - end)(from_list([{4, 0}, {1, 0}]))). + expect:false(has_key(from_list([]), 1)), + expect:true(has_key(from_list([{1, 0}]), 1)), + expect:true(has_key(from_list([{4, 0}, {1, 0}]), 1)), + expect:false(has_key(from_list([{4, 0}, {1, 0}]), 0)). -endif. new() -> @@ -45,8 +39,8 @@ new() -> -ifdef(TEST). new_test() -> - (fun(Capture1) -> expect:equal(Capture1, 0) end)(size(new())), - (fun(Capture1) -> expect:equal(Capture1, []) end)(to_list(new())). + expect:equal(size(new()), 0), + expect:equal(to_list(new()), []). -endif. fetch(A, B) -> @@ -56,12 +50,8 @@ fetch(A, B) -> fetch_test() -> Proplist = [{4, 0}, {1, 1}], Map = from_list(Proplist), - (fun(Capture1) -> - expect:equal(Capture1, {ok, 0}) - end)((fun(Capture1) -> fetch(Capture1, 4) end)(Map)), - (fun(Capture1) -> - expect:equal(Capture1, {ok, 1}) - end)((fun(Capture1) -> fetch(Capture1, 1) end)(Map)). + expect:equal(fetch(Map, 4), {ok, 0}), + expect:equal(fetch(Map, 1), {ok, 1}). -endif. erl_put(A, B, C) -> @@ -72,14 +62,8 @@ put(Map, Key, Value) -> -ifdef(TEST). put_test() -> - (fun(Capture1) -> - expect:equal(Capture1, - from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])) - end)((fun(Capture1) -> - put(Capture1, <<"c">>, 2) - end)((fun(Capture1) -> - put(Capture1, <<"b">>, 1) - end)((fun(Capture1) -> put(Capture1, <<"a">>, 0) end)(new())))). + expect:equal(put(put(put(new(), <<"a">>, 0), <<"b">>, 1), <<"c">>, 2), + from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])). -endif. erl_map_values(A, B) -> @@ -90,11 +74,9 @@ map_values(Map, Fun) -> -ifdef(TEST). map_values_test() -> - (fun(Capture1) -> - expect:equal(Capture1, from_list([{1, 1}, {2, 3}, {3, 5}])) - end)((fun(Capture1) -> - map_values(Capture1, fun(K, V) -> K + V end) - end)(from_list([{1, 0}, {2, 1}, {3, 2}]))). + expect:equal(map_values(from_list([{1, 0}, {2, 1}, {3, 2}]), + fun(K, V) -> K + V end), + from_list([{1, 1}, {2, 3}, {3, 5}])). -endif. keys(A) -> @@ -102,9 +84,8 @@ keys(A) -> -ifdef(TEST). keys_test() -> - (fun(Capture1) -> - expect:equal(Capture1, [<<"a">>, <<"b">>, <<"c">>]) - end)(keys(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). + expect:equal(keys(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])), + [<<"a">>, <<"b">>, <<"c">>]). -endif. values(A) -> @@ -112,9 +93,8 @@ values(A) -> -ifdef(TEST). values_test() -> - (fun(Capture1) -> - expect:equal(Capture1, [0, 1, 2]) - end)(values(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). + expect:equal(values(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])), + [0, 1, 2]). -endif. erl_filter(A, B) -> diff --git a/gen/order.erl b/gen/order.erl index e970ee7..92e6f13 100644 --- a/gen/order.erl +++ b/gen/order.erl @@ -18,9 +18,9 @@ reverse(Order) -> -ifdef(TEST). reverse_test() -> - (fun(Capture1) -> expect:equal(Capture1, gt) end)(reverse(lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(reverse(eq)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(reverse(gt)). + expect:equal(reverse(lt), gt), + expect:equal(reverse(eq), eq), + expect:equal(reverse(gt), lt). -endif. to_int(Order) -> @@ -37,9 +37,9 @@ to_int(Order) -> -ifdef(TEST). to_int_test() -> - (fun(Capture1) -> expect:equal(Capture1, -1) end)(to_int(lt)), - (fun(Capture1) -> expect:equal(Capture1, 0) end)(to_int(eq)), - (fun(Capture1) -> expect:equal(Capture1, 1) end)(to_int(gt)). + expect:equal(to_int(lt), -1), + expect:equal(to_int(eq), 0), + expect:equal(to_int(gt), 1). -endif. compare(A, B) -> @@ -65,15 +65,15 @@ compare(A, B) -> -ifdef(TEST). compare_test() -> - (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(lt, lt)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(lt, eq)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(lt, gt)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(eq, lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(eq, eq)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(eq, gt)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(gt, lt)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(gt, eq)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(gt, gt)). + expect:equal(compare(lt, lt), eq), + expect:equal(compare(lt, eq), lt), + expect:equal(compare(lt, gt), lt), + expect:equal(compare(eq, lt), gt), + expect:equal(compare(eq, eq), eq), + expect:equal(compare(eq, gt), lt), + expect:equal(compare(gt, lt), gt), + expect:equal(compare(gt, eq), gt), + expect:equal(compare(gt, gt), eq). -endif. max(A, B) -> @@ -90,15 +90,15 @@ max(A, B) -> -ifdef(TEST). max_test() -> - (fun(Capture1) -> expect:equal(Capture1, lt) end)(max(lt, lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(lt, eq)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(lt, gt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(eq, lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(eq, eq)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(eq, gt)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, lt)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, eq)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, gt)). + expect:equal(max(lt, lt), lt), + expect:equal(max(lt, eq), eq), + expect:equal(max(lt, gt), gt), + expect:equal(max(eq, lt), eq), + expect:equal(max(eq, eq), eq), + expect:equal(max(eq, gt), gt), + expect:equal(max(gt, lt), gt), + expect:equal(max(gt, eq), gt), + expect:equal(max(gt, gt), gt). -endif. min(A, B) -> @@ -115,13 +115,13 @@ min(A, B) -> -ifdef(TEST). min_test() -> - (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, lt)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, eq)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, gt)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(eq, lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(eq, eq)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(eq, gt)), - (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(gt, lt)), - (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(gt, eq)), - (fun(Capture1) -> expect:equal(Capture1, gt) end)(min(gt, gt)). + expect:equal(min(lt, lt), lt), + expect:equal(min(lt, eq), lt), + expect:equal(min(lt, gt), lt), + expect:equal(min(eq, lt), lt), + expect:equal(min(eq, eq), eq), + expect:equal(min(eq, gt), eq), + expect:equal(min(gt, lt), lt), + expect:equal(min(gt, eq), eq), + expect:equal(min(gt, gt), gt). -endif. diff --git a/gen/result.erl b/gen/result.erl index 266b41f..b52cadd 100644 --- a/gen/result.erl +++ b/gen/result.erl @@ -45,12 +45,8 @@ map(Result, Fun) -> -ifdef(TEST). map_test() -> - (fun(Capture1) -> - expect:equal(Capture1, {ok, 2}) - end)((fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end)({ok, 1})), - (fun(Capture1) -> - expect:equal(Capture1, {error, 1}) - end)((fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end)({error, 1})). + expect:equal(map({ok, 1}, fun(X) -> X + 1 end), {ok, 2}), + expect:equal(map({error, 1}, fun(X) -> X + 1 end), {error, 1}). -endif. map_error(Result, Fun) -> @@ -64,16 +60,8 @@ map_error(Result, Fun) -> -ifdef(TEST). map_error_test() -> - (fun(Capture1) -> - expect:equal(Capture1, {ok, 1}) - end)((fun(Capture1) -> - map_error(Capture1, fun(X) -> X + 1 end) - end)({ok, 1})), - (fun(Capture1) -> - expect:equal(Capture1, {error, 2}) - end)((fun(Capture1) -> - map_error(Capture1, fun(X) -> X + 1 end) - end)({error, 1})). + expect:equal(map_error({ok, 1}, fun(X) -> X + 1 end), {ok, 1}), + expect:equal(map_error({error, 1}, fun(X) -> X + 1 end), {error, 2}). -endif. flatten(Result) -> @@ -87,18 +75,10 @@ flatten(Result) -> -ifdef(TEST). flatten_test() -> - (fun(Capture1) -> - expect:equal(Capture1, {ok, 1}) - end)(flatten({ok, {ok, 1}})), - (fun(Capture1) -> - expect:equal(Capture1, {error, 1}) - end)(flatten({ok, {error, 1}})), - (fun(Capture1) -> - expect:equal(Capture1, {error, 1}) - end)(flatten({error, 1})), - (fun(Capture1) -> - expect:equal(Capture1, {error, {error, 1}}) - end)(flatten({error, {error, 1}})). + expect:equal(flatten({ok, {ok, 1}}), {ok, 1}), + expect:equal(flatten({ok, {error, 1}}), {error, 1}), + expect:equal(flatten({error, 1}), {error, 1}), + expect:equal(flatten({error, {error, 1}}), {error, {error, 1}}). -endif. flat_map(Result, Fun) -> @@ -118,21 +98,9 @@ flat_map(Result, Fun) -> -ifdef(TEST). flat_map_test() -> - (fun(Capture1) -> - expect:equal(Capture1, {error, 1}) - end)((fun(Capture1) -> - flat_map(Capture1, fun(X) -> {ok, X + 1} end) - end)({error, 1})), - (fun(Capture1) -> - expect:equal(Capture1, {ok, 2}) - end)((fun(Capture1) -> - flat_map(Capture1, fun(X) -> {ok, X + 1} end) - end)({ok, 1})), - (fun(Capture1) -> - expect:equal(Capture1, {error, 1}) - end)((fun(Capture1) -> - flat_map(Capture1, fun(Unused) -> {error, 1} end) - end)({ok, 1})). + expect:equal(flat_map({error, 1}, fun(X) -> {ok, X + 1} end), {error, 1}), + expect:equal(flat_map({ok, 1}, fun(X) -> {ok, X + 1} end), {ok, 2}), + expect:equal(flat_map({ok, 1}, fun(_) -> {error, 1} end), {error, 1}). -endif. unwrap(Result, Default) -> @@ -146,8 +114,6 @@ unwrap(Result, Default) -> -ifdef(TEST). unwrap_test() -> - (fun(Capture1) -> expect:equal(Capture1, 1) end)(unwrap({ok, 1}, 50)), - (fun(Capture1) -> - expect:equal(Capture1, 50) - end)(unwrap({error, <<"nope">>}, 50)). + expect:equal(unwrap({ok, 1}, 50), 1), + expect:equal(unwrap({error, <<"nope">>}, 50), 50). -endif. |