Last active
February 23, 2019 06:34
-
-
Save Dimanaux/23531abb48b96d3a09ba617a7f790844 to your computer and use it in GitHub Desktop.
Some examples of simple functions in Erlang
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(task). | |
-export([words_count/1, count/1, check/1]). | |
words_count(S) -> iter(0, false, S). | |
iter(W, _ , [] ) -> W; | |
iter(W, _ , [32 | Tail]) -> iter(W , false, Tail); | |
iter(W, false, [_ | Tail]) -> iter(W + 1, true , Tail); | |
iter(W, _ , [_ | Tail]) -> iter(W , true , Tail). | |
count(10) -> [10]; | |
count(T ) -> [T | count(T + 1)]. | |
check(success) -> "success"; | |
check({error, Message}) -> "error: " ++ Message. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment