Sha256: 7c944c922692c9a837e85ef0bd1f827f26f2b6dff8a16977948b96f33ddce5e4

Contents?: true

Size: 683 Bytes

Versions: 84

Compression:

Stored size: 683 Bytes

Contents

-module(bob).

-export([response_for/1]).

-spec response_for(string()) -> string().
response_for(String) ->
  first_match(
    String,
    [{fun is_all_spaces/1, "Fine. Be that way!"},
     {fun is_shouting/1, "Whoa, chill out!"},
     {fun is_question/1, "Sure."},
     {fun (_) -> true end, "Whatever."}]).

first_match(S, [{F, Res} | Fs]) ->
  case F(S) of
    true -> Res;
    false -> first_match(S, Fs)
  end.

is_shouting(String) ->
  lists:any(fun (C) -> C >= $A andalso C =< $Z end, String) andalso
  string:to_upper(String) =:= String.

is_question(String) ->
  lists:last(String) =:= $?.

is_all_spaces(String) ->
  re:run(String, "^(\\h|\\v)*$", [unicode]) =/= nomatch.

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.1.2 tracks/erlang/exercises/bob/example.erl
trackler-2.0.1.1 tracks/erlang/exercises/bob/example.erl
trackler-2.0.1.0 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.10 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.9 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.8 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.7 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.6 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.5 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.4 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.3 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.2 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.1 tracks/erlang/exercises/bob/example.erl
trackler-2.0.0.0 tracks/erlang/exercises/bob/example.erl
trackler-1.0.4.1 tracks/erlang/exercises/bob/example.erl
trackler-1.0.4.0 tracks/erlang/exercises/bob/example.erl
trackler-1.0.3.0 tracks/erlang/exercises/bob/example.erl
trackler-1.0.2.1 tracks/erlang/exercises/bob/example.erl
trackler-1.0.2.0 tracks/erlang/exercises/bob/example.erl
trackler-1.0.1.2 tracks/erlang/exercises/bob/example.erl