-
Notifications
You must be signed in to change notification settings - Fork 66
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
Proposal: unique
and option
-alike combinators
#518
Comments
I like the idea of these methods, but the proposed name seems a little ambiguous and uncertain. I'm more concerned about 'unique', which in the context of SQL seems fine, but outside of that scope, it could imply that the element is distinct in some way, rather than just that the collection contains exactly one element. |
I would be happy to merge a PR with these additions. I agree with @danicheg's points re: naming. I like ensureSole and ensureSoleOrEmpty myself. |
@danicheg , @benhutchison , thank you for your feedback! Yes, I agree that we should choose better names – I picked those just to have something to start with. Regarding the suggested ones. At first I favored the |
Another thing that I feel it is important to think through. Initially, I proposed the However, there's another one in Cats – Therefore I think that perhaps it would be beneficial to give it a shot and add the missing combinators to Thank you! |
@satorg It's clear youve given this a lot of thought. I'll back whichever choice you come to in terms of Seems depending on |
Maintaining naming consistency is crucial within a single abstraction, though it's not that big of a deal, since we don't have a universally agreed-upon language. Regarding the |
Just to clarify, are you suggesting something like this:
? In that case, the first method wouldn't allow to tell apart a valid |
What stops us from having |
@danicheg the bit that confused me was..
Shouldn't Id expect ... is that what you were thinking of? |
I was suggesting adding |
Ah, got you. I feel |
Inspired by Doobie's
unique
andoption
queries:https://github.com/typelevel/doobie/blob/1ad3ad5e195d89becbd4097677f738a0b10aa5df/modules/core/src/main/scala/doobie/util/query.scala#L127-L139
In fact, those two are pretty common use cases: after receiving a collection of items from somewhere, we may want to make sure that there's either exactly 1 or at most 1 items received.
To make them generally available, we could consider adding two combinators to
FNested2SyntaxOps
:The proposed names may not be perfect – just got borrowed them from Doobie. However, I'm absolutely open for bikeshedding.
If such combinators make sense, I'll be glad to file a PR.
The text was updated successfully, but these errors were encountered: