As someone who only tried a few functional libraries (Jane Street Base, Belt, @most/core, and a bit of Elm) I find the frist two names the most clear for collections. Then again, forEach
, IMHO, sounds a little silly for types that basically wrap a single value.
tap
sounds familiar too, but I’m not even sure if its similarity with Fun.tap
(which can be seen as the same tap
, but for a naked value insdead of the values inside a collection) helps or confuses. Then again, with Option.tap
or Result.tap
it’s beginning to dawn on me, and maybe it’s even the best of all because it doesn’t imply iterating over multiple values.
But overall, I think maybe you have to look at it in a wider context, use the principle of least surprise and make things more consistent and easier to memorize? Do you want Set.iter
, List.iter
, Option.iter
, but Fun.tap
? Thats one boundary. Set.forEach
, List.forEach
, Option.tap
and Fun.tap
. Fine too, I guess, as long as it’s Result.tap
(not forEach
) as well, and Array.forEach
(not tap
). Going iter
(or tap
) all the way, including Fun.iter
? Even better (arguably).
I think consistency beats familiarity even in the middle run (and Reason actualy shines in the long run, and will probably stay that way for quite a while, if not indefinitely). So don’t really care about forEach
.