Last active
March 6, 2017 19:46
-
-
Save jason-carter/ba9b86231aee9d94f162cc17de9fd07b to your computer and use it in GitHub Desktop.
FutureLearn Functional Programming In Erlang 2.11: Where do I begin
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
-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