Simple way to convert expression to a list?
Like J.M. wrote, the question is if the expression is atomic, because Apply
doesn't work on atomic expressions.
If we disambiguate the two cases we should be fine:
Listify = If[AtomQ[#], {#}, List @@ #]&
Listify[42]
(* {42} *)
Listify[foo[1, 2, 3]]
(* {1, 2, 3} *)
ClearAll[toList]
toList = # /. { _[a__] :> {a}, a_?AtomQ :> {a}} &;
Examples:
list = {2, a, foo[a, b], s + t + u, Rational[1, 3],
Complex[5, 6], <|a -> x, b -> y, c -> z|>, DateObject[]};
Grid[Prepend[Transpose[{list, toList /@ list}],
Item[#, Background -> LightBlue] & /@ {"expr", "toList@expr"}],
Dividers -> All]