Skip to content

Instantly share code, notes, and snippets.

@Ceroce
Created July 6, 2017 07:46
Show Gist options
  • Save Ceroce/ff3aa039c7ee1ce66b6e66e1cfc878c9 to your computer and use it in GitHub Desktop.
Save Ceroce/ff3aa039c7ee1ce66b6e66e1cfc878c9 to your computer and use it in GitHub Desktop.
-module (take).
-export ([take/2]).
% Take the first N elements of a list.
% N may be larger than the length of the list, in which case the whole list is returned.
-spec take(integer(),[T]) -> [T].
take(0, _) -> [];
take(_,[]) -> [];
take(N,[X|Xs]) -> [X|take(N-1, Xs)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment