Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -export([any/2, all/2]).
- -include_lib("eunit/include/eunit.hrl").
- %% BEGIN (write your solution here)
- any(_, []) -> false;
- any(Pred, [H|T]) -> Pred(H) orelse Pred([H|T]).
- %% END
- any_test() ->
- F1 = fun(V) -> V > 10 end,
- ?assertEqual(true, any(F1, [10, 20, 30])),
- ?assertEqual(false, any(F1, [1, 2, 3])),
- ?assertEqual(false, any(F1, [])),
- F2 = fun(V) -> V rem 2 =:= 0 end,
- ?assertEqual(true, any(F2, [1, 2, 3])),
- ?assertEqual(false, any(F2, [1, 3, 5])),
- ok.
- %% BEGIN (write your solution here)
- all(_, []) -> true;
- all(Pred, [H|T]) -> Pred(H) andalso Pred([H|T]).
- %% END
- all_test() ->
- F1 = fun(V) -> V >= 10 end,
- ?assertEqual(true, all(F1, [10, 20, 30])),
- ?assertEqual(false, all(F1, [1, 20, 30])),
- ?assertEqual(true, all(F1, [])),
- F2 = fun(V) -> V rem 2 =:= 0 end,
- ?assertEqual(true, all(F2, [4, 6, 8])),
- ?assertEqual(false, all(F2, [2, 3, 4])),
- ok.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement