Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map a void (non-returning function) over an array

Title is self-explanatory, is there any way of mapping, for example, addGestureRecognizer over an array of UIGestureRecognizers. I've been fiddling around with variations of

recognizers.map(MyWebOutlet.addGestureRecognizer)

but since built-in map has to return another array in requires a function that returns some kind of value. Should I just wrap addGestureRecognizer in another returning function or is the another cleverer way?

like image 967
TedNC Avatar asked Sep 13 '25 04:09

TedNC


1 Answers

map is designed to return an array from another array that has had a given transformation applied to it (by transforming each element). Therefore naturally the function that you pass to it has to return the transformed element.

In your case, you're not actually transforming the elements, you just want to use them in an argument of a function. To do this, you can use forEach.

recognizers.forEach(MyWebOutlet.addGestureRecognizer)
like image 101
Hamish Avatar answered Sep 15 '25 18:09

Hamish