Created
March 18, 2012 22:58
-
-
Save hgarcia/2083943 to your computer and use it in GitHub Desktop.
Lerning Erlang 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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