fknop / angular-pipes

Useful pipes for Angular
https://fknop.gitbook.io/angular-pipes/
MIT License
732 stars 157 forks source link

missing 'first' pipe #41

Closed nirsalon closed 7 years ago

nirsalon commented 7 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request

Current behavior No pipe returns the first element that matches a condition

Expected behavior A new pipe, similar to 'where', that returns the first element that matches the condition See .NET linq .First() https://msdn.microsoft.com/en-us/library/bb535050(v=vs.110).aspx

What is the motivation / use case for changing the behavior? A more performant pipe than (arr | where:[cond])[0]

fknop commented 7 years ago

That's a good idea, what about the firstWhere name ?

nirsalon commented 7 years ago

C# uses First(), and FirstOrDefault() which doesn't throw if not found Java 8 uses findFirst() Usually function names are either verb or 'verbNoun', so I'd say something like first/firstMatch/findFirst, but firstWherealso work.

fknop commented 7 years ago

I think I'll go with firstOrDefault.

I'll probably implement that with https://github.com/fknop/angular-pipes/issues/40 tonight or tomorrow.