Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
It's pretty easy to write a function that returns at the first match in a set. Get on it ;)
-
alert2504y@SortOfTested yeah I know, but that's so obvious it should be in builtins
If we have any(), then why no alternative that returns the element -
@dhvcc I'm suggesting a wrapper buut it's in JS. Think it like a psuedo code.
@highlight
/* global:somePatternMatcher*/
//Use this to match element
/* global:set*/
//The set we are searching in
//the this context is Set.
function first(matcher){
let foundElement;
this.any(elem =>{
return matcher(elem) &&
(foundElement= elem)
});
return foundElement;
}
//usage 1. (Not recommended)
Set.prototype.first = first;
set.first(somePatternMatcher);
//usage 2.
var setFirst = first.bind(set);
setFirst(somePatternMatcher); -
alert2504y@melezorus34
I don't need the code for the function, I can write it myself
I'm just ranting that it's not in builtins :)
We already have itertools, with filter and other goodies
But built-in first would be a much cleaner way of doing this
Related Rants
Python builtins are great
But why the fuck there is STILL no first() function
It's mildlyinfuriating
rant
python
mildlyinfuriating