X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=src%2Fhope_list.erl;h=f179d1a054a2dabb46351eef14bf81e64aa9bc8f;hb=532e045d6052ffcb0dc778ac013658083d1df466;hp=abfb3d39ca74aa61f38a360ef502b5e1a2f7d6a9;hpb=781f182fe399d95fc144ba3b47112e803ba6af6e;p=hope.git diff --git a/src/hope_list.erl b/src/hope_list.erl index abfb3d3..f179d1a 100644 --- a/src/hope_list.erl +++ b/src/hope_list.erl @@ -10,6 +10,7 @@ , map/3 % Tunable recursion limit , map_rev/2 , map_slow/2 + , first_match/2 ]). @@ -102,3 +103,13 @@ unique_preserve_order(L) -> end end, lists:reverse(lists:foldl(PrependIfNew, [], L)). + +-spec first_match([{Tag, fun((A) -> boolean())}], A) -> + hope_option:t(Tag). +first_match([], _) -> + none; +first_match([{Tag, F} | Tests], X) -> + case F(X) + of true -> {some, Tag} + ; false -> first_match(Tests, X) + end.