diff options
Diffstat (limited to 'gen/src')
-rw-r--r-- | gen/src/list.erl | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gen/src/list.erl b/gen/src/list.erl index 1395112..8df10f6 100644 --- a/gen/src/list.erl +++ b/gen/src/list.erl @@ -1,7 +1,7 @@ -module(list). -compile(no_auto_import). --export([length/1, reverse/1, is_empty/1, contains/2, head/1, tail/1, filter/2, map/2, index_map/2, traverse/2, drop/2, take/2, new/0, append/2, flatten/1, fold/3, fold_right/3, find/2, all/2, any/2, zip/2, strict_zip/2, intersperse/2, at/2, unique/1, sort/1, range/2, repeat/2, split/2]). +-export([length/1, reverse/1, is_empty/1, contains/2, head/1, tail/1, filter/2, map/2, index_map/2, traverse/2, drop/2, take/2, new/0, append/2, flatten/1, fold/3, fold_right/3, find/2, all/2, any/2, zip/2, strict_zip/2, intersperse/2, at/2, unique/1, sort/1, range/2, repeat/2, split/2, split_while/2]). length(A) -> erlang:length(A). @@ -349,3 +349,21 @@ do_split(List, N, Taken) -> split(List, N) -> do_split(List, N, []). + +do_split_while(List, F, Acc) -> + case List of + [] -> + {reverse(Acc), []}; + + [X | Xs] -> + case F(X) of + false -> + {reverse(Acc), List}; + + _ -> + do_split_while(Xs, F, [X | Acc]) + end + end. + +split_while(List, F) -> + do_split_while(List, F, []). |