If the argument is a symbol return it. If the argument is a list call another method.
New to Clojure and cannot find the canonical way to do it. In Python, one could do:
def return_on_arg_type(arg):
if type(arg) is str:
return arg
if type(arg) is list:
return another_method(arg)
May be I could use multi-methods but how to match on type of the argument and also is matching on type acceptable in Clojure?
There's essentially 3 dispatch methods in Clojure:
cond
combined with predicates (that's methods that return true or false and often have a name ending in ?
) as Alan has described.Take a look at Clojure multimethods vs. protocols for a short discussion on Multimethods vs Protocols.