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