function foo(arg1, arg2, arg3)
arg1 + arg2 + arg3
end
map(foo, [1;2;3], [4;5;6], 5)
This code is equivalent to [foo(1, 4, 5)], the other values discarded.
Is this behavior desired for any reason? It doesn’t appear to be documented, and I naively thought that a scalar would be broadcasted.
If c was an array, there’s a DimensionMismatch error, so it isn’t as if it always takes the smallest set it can apply.
Thus, should map(foo, [1;2;3], [4;5;6], 5) throw an error, forcing the user to turn it into an array of the necessary size; or should it broadcast the scalar internally?
My guess is that this is unintended. It happens because map calls zip, and zip stops iterating once the shortest iterator (i.e. the scalar) is exhausted. (This behavior of zip is documented.)
The reason it does not throw a DimensionMistmatch is that Base.IteratorSize(zip(1:2, 1)) hits a fallback function that simply returns SizeUnknown() and this causes the dimension check to be bypassed.
Making this an error would be breaking, but I’d say it’s worth it since any code that it breaks is likely to be buggy. Users should be forced to specify either map(+, first(1:2), 1) or map(+, 1:2, Iterators.repeated(1)) depending on what they meant.