Skip to content

Instantly share code, notes, and snippets.

@jason-carter
Last active March 6, 2017 19:46
Show Gist options
  • Save jason-carter/ba9b86231aee9d94f162cc17de9fd07b to your computer and use it in GitHub Desktop.
Save jason-carter/ba9b86231aee9d94f162cc17de9fd07b to your computer and use it in GitHub Desktop.
FutureLearn Functional Programming In Erlang 2.11: Where do I begin
-module(take).
-export([take/2, take_test/0]).
-spec take(integer(), [T]) -> [T].
take(0, _) -> [];
take(_, []) -> [];
take(Cnt, [X|Xs]) when Cnt > 0 -> [X | take(Cnt-1, Xs)].
take_test() ->
[] = take(0,"hello"),
"hell" = take(4,"hello"),
"hello" = take(5,"hello"),
"hello" = take(9,"hello"),
take_test_passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment