Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api should match Linq (Single, First => SingleOption, FirstOption) #172

Open
Baccanno opened this issue Jun 10, 2020 · 2 comments
Open

Api should match Linq (Single, First => SingleOption, FirstOption) #172

Baccanno opened this issue Jun 10, 2020 · 2 comments

Comments

@Baccanno
Copy link

Baccanno commented Jun 10, 2020

In this issue you seem to have introduced an option type for some of the linq functions,
#133

However Linq original First and Hyperlinq first now have a different signature. Wouldn't it feel better to specify a new signature such as FirstOpt, FirstOption ? Actually this is what I've done for my own set of Linq extension methods.

It also prevents Hyperlinq to be a drag&drop solution as it will cause regression.

@aalmada
Copy link
Member

aalmada commented Jun 10, 2020

Hi @Baccanno

Thank you for your feedback.

Hyperlinq is not drag&drop in several cases. IEnumerable<> collections have to be converted to IValueEnumerable<> and IReadOnlyCollection<,> collections have to be converted to IValueReadOnlyCollection<,>. The operation AsValueEnumerable() has to be used for that. It's not required for arrays, Span<>, Memory<>, collections in System.Collections.Generic and in System.Collections.Immutable, because I have extensions for those.

My initial plan was to reproduce the LINQ API as much as possible. I since then changed my mind. I want to create a modern version of LINQ.

I did support First, Single, ElementAt, FirstOrDefault, SingleOrDefault and ElementAtOrDefault. The reason I longer do is that I have to implement them for arrays, Span, ReadOnlySpan, Memory, ReadOnlyMemory, IValueEnumerable, IValueReadOnlyCollection, IReadOnlyList, and IAsyncValueEnumerable. Plus, I have to have unit tests for all of these. I already have more than 7K unit test scenarios.

In #133 I explain all the alternatives I considered. I ended up choosing to return Option.

In this project, I already use source generators. I may consider your naming proposal and use generators to generate the extensions required to support the old behaviors.

@Baccanno
Copy link
Author

Baccanno commented Jun 10, 2020

Thanks for you thorough answer. I indeed believe you should stick with LINQ original naming when signature & behaviour are the same. If behaviour or signature changes then I would set a new name. I feel it's the best practice in what you're trying to create to avoid any headache to developers adopting your solution.

Not being drag & drop is not an issue in itself. Just misleading naming :)

I'm envisioning to try Hyperlinq out in the optimization process of Unity games where heap allocation is an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants