2 ms·
There might be a good alternative. Sometimes it's that one function right in the case expression that prevents lifting the matching to the function head (which
by strmpnk 10y ago
There might be a good alternative. Sometimes it's that one function right in the case expression that prevents lifting the matching to the function head (which is considered good style in Erlang).
To do this you could try wrapping the list:foreach itself rather than worry about the inner function, leading to something which seems more concise and in one piece, leaving the more generic iteration to a well named function:
-spec do_whatever(Keys, SomeParameter) -> ok when
Keys :: [some_kind_of_key()],
SomeParameter :: term().
do_whatever(Keys, SomeParameter) ->
lookup_each(fun
({ok, Value}) -> do_side_effecty_thing(Value, SomeParameter);
({error, Reason}) -> report_some_failure(Reason)
end, Keys).
lookup_each(Fn, Keys) ->
lists:foreach(fun (Key) -> Fn(external_lookup(Key)) end, Keys).