I’d like to write some code that easily handles the input to be either a single value or an array and perform an operation on either the single value or each value in the array.
Ideally the code would just look like:
a = for i in j()
i++
but j could return either 1 or [1, 2, 3].
I don’t even see a good way to somehow check to see if j returns an array. Maybe coffeescript has some good type identification system so I could do
if j().isArray then j() else [j()]
or something?
Anyone know of a syntactically appealing way of hiding this array conversion logic as much as possible?
will copy the result if array, wrap otherwise.