Normally in ActionScript methods such as every, some (or all/any ) and reduce are built-in in Array. In JavaScript, String comes with trim. Haxe implements StringTools.trim(s) instead of s.trim.
Is it because of reflection or target-platform reason?
Update
using StringTools; as mentioned by Gama11 resolves s.trim.
Does anyone know why Array hasn’t some methods like I mentioned?
Update (2)
using Lambda; provides additional Array methods, however I found the naming conventions out of the standard:
Would be nice to have more array/string methods without import hacks and libraries tho. What a point to have single String extension class in std? It’s only makes difficult to find basic string features for new users.
For array methods there is using Lamda; which has a couple functions.
As for why these are in separate classes, I’d guess it is for historical reasons, maybe at some point method couldn’t be added in base classes if a target didn’t have support for it, and now it stayed like that.
But it does make it harder to find these functions.
It doesn’t seem bad to have a class providing these extension methods. Though it seems like Lambda doesn’t have reduce and other functional programming methods (like any/all), which anyone would expect, since Haxe is old.
it seems like both String and Array have static extensions for methods that a lot of devs expect to find out-of-box. I don’t think these classes would seem crowded if we exposed them at all times
One upside I see in putting these in static extensions is that it makes it possible to provide alternative implementations of these methods without having to actually touch the original String type.