Skip to content

Instantly share code, notes, and snippets.

@Dimanaux
Last active February 23, 2019 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimanaux/23531abb48b96d3a09ba617a7f790844 to your computer and use it in GitHub Desktop.
Save Dimanaux/23531abb48b96d3a09ba617a7f790844 to your computer and use it in GitHub Desktop.
Some examples of simple functions in Erlang
-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