home
/
code
/
hope.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
8fc25ea
)
Add hope_list:unique_preserve_order/1
author
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 7 Aug 2014 16:39:25 +0000
(12:39 -0400)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 7 Aug 2014 16:39:25 +0000
(12:39 -0400)
src/hope_list.erl
[new file with mode: 0644]
patch
|
blob
diff --git a/src/hope_list.erl
b/src/hope_list.erl
new file mode 100644
(file)
index 0000000..
5ce527c
--- /dev/null
+++ b/
src/hope_list.erl
@@ -0,0
+1,26
@@
+-module(hope_list).
+
+-export_type(
+ [ t/1
+ ]).
+
+-export(
+ [ unique_preserve_order/1
+ ]).
+
+
+-type t(A) ::
+ [A].
+
+
+-spec unique_preserve_order(t(A)) ->
+ t(A).
+unique_preserve_order(L) ->
+ AppendIfNew =
+ fun (X, Xs) ->
+ case lists:member(X, Xs)
+ of true -> Xs
+ ; false -> Xs ++ [X]
+ end
+ end,
+ lists:foldl(AppendIfNew, [], L).
This page took
0.029254 seconds
and
4
git commands to generate.