Skip to content

Instantly share code, notes, and snippets.

@hgarcia
Created March 18, 2012 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgarcia/2083943 to your computer and use it in GitHub Desktop.
Save hgarcia/2083943 to your computer and use it in GitHub Desktop.
Lerning Erlang 2
1> lists:partition(fun(X) -> X rem 2 == 1 end, lists:seq(0, 20)).
{[1,3,5,7,9,11,13,15,17,19], [0,2,4,6,8,10,12,14,16,18,20]}
1> lists:seq(0, 10).
[0,1,2,3,4,5,6,7,8,9,10]
2> lists:seq(0, 12, 3).
[0,3,6,9,12]
1> lists:sublist([2,3,4,5,6,7,8], 5). %% 5 is the length of the new list
[2,3,4,5,6]
2> lists:sublist([2,3,4,5,6,7,8], 2, 3). %%2 is the start and 3 the length for the new list
[3,4,5]
3> lists:split(4, [1,2,3,4,5,6,7,8,0]). %%4 is the split point
{[1,2,3,4],[5,6,7,8,0]}
4> lists:splitwith(fun(A) -> A < 3 end, [0,1,2,3,4,5,6,7]). %% fun == true first list; false, second list
{[0,1,2],[3,4,5,6,7]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment