X-Git-Url: https://git.xandkar.net/?p=hope.git;a=blobdiff_plain;f=src%2Fhope_list.erl;h=f179d1a054a2dabb46351eef14bf81e64aa9bc8f;hp=abfb3d39ca74aa61f38a360ef502b5e1a2f7d6a9;hb=a626cf31904f7d782c8c9756adc4279b0dd5db66;hpb=e163be89d2e192e63fdc03b66146067d92b21e1f 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.