On Sun, Aug 30, 2020 at 6:13 PM tyson andre <tysonandre...@hotmail.com> wrote:
> > I like this, but I do not like the flags. I don't think they're at all > useful. A lot of the other discussion in the thread seems to be needlessly > complicating it, too. > > > > all() and any() only need return booleans. Their callbacks only need > return booleans. That's the point. first() makes sense to add, and it > would return the first value that matches. > > What would first() return on failure? Would it throw (inefficient)? > Would it set an optional output reference to distinguish between returning > the value null from an iterable and the null from no matches? > If it took the default value as well it could return that. While it's useful in itself it also would enable you to pass a marker object and check the identity of that to know if no matches have been found: $none = new stdClass; $element = first($collection, fn($elt) => ...); if ($element === $none) { // nothing found } -- Best regards, Bruce Weirdan mailto: weir...@gmail.com