aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-04-29 09:54:12 +0200
committerBjörn Gustavsson <[email protected]>2016-04-29 09:54:12 +0200
commit06fe4914224a7172a60d318e15885841981b746d (patch)
tree030df2277391ee052f77df65fb6da1c133d39f3d /lib/stdlib/src
parente142c20d5d751c0b9ba8c059249097b459ac329e (diff)
parentc660e30a7dd781f71bed050b20c3e2d0b069e063 (diff)
downloadotp-06fe4914224a7172a60d318e15885841981b746d.tar.gz
otp-06fe4914224a7172a60d318e15885841981b746d.tar.bz2
otp-06fe4914224a7172a60d318e15885841981b746d.zip
Merge branch 'jlouis/stdlib/implement-lists-join/PR-1012/OTP-13523'
* jlouis/stdlib/implement-lists-join/PR-1012/OTP-13523: Implement lists:join/2
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/lists.erl15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/stdlib/src/lists.erl b/lib/stdlib/src/lists.erl
index 2b4472cdf7..af9d63ddd6 100644
--- a/lib/stdlib/src/lists.erl
+++ b/lib/stdlib/src/lists.erl
@@ -39,7 +39,8 @@
-export([all/2,any/2,map/2,flatmap/2,foldl/3,foldr/3,filter/2,
partition/2,zf/2,filtermap/2,
mapfoldl/3,mapfoldr/3,foreach/2,takewhile/2,dropwhile/2,splitwith/2,
- split/2]).
+ split/2,
+ join/2]).
%%% BIFs
-export([keyfind/3, keymember/3, keysearch/3, member/2, reverse/2]).
@@ -1439,6 +1440,18 @@ split(N, [H|T], R) ->
split(_, [], _) ->
badarg.
+-spec join(Sep, List1) -> List2 when
+ Sep :: T,
+ List1 :: [T],
+ List2 :: [T],
+ T :: term().
+
+join(_Sep, []) -> [];
+join(Sep, [H|T]) -> [H|join_prepend(Sep, T)].
+
+join_prepend(_Sep, []) -> [];
+join_prepend(Sep, [H|T]) -> [Sep,H|join_prepend(Sep,T)].
+
%%% =================================================================
%%% Here follows the implementation of the sort functions.
%%%