[erlang-questions] Ternary Like Operation Idiom in Erlang
Jarrod Roberson
jarrod@REDACTED
Wed Dec 2 23:10:18 CET 2009
Thanks to Dale's version I came up with this.
F = fun(T) -> case re:split(T,"=",[{return,list}]) of [K] -> {K,true};
[K,V] -> {K,V} end end.
in action
Eshell V5.7.3 (abort with ^G)
1> F = fun(T) -> case re:split(T,"=",[{return,list}]) of [K] ->
{K,true}; [K,V] -> {K,V} end end.
#Fun<erl_eval.6.13229925>
2> F("key").
{"key",true}
3> F("key=value").
{"key","value"}
4> F("key=").
{"key",[]}
5>
More information about the erlang-questions
mailing list