Create FS-1135-map-binary-search.md#734
Conversation
|
@KevinRansom @vzarytovskii @abelbraaksma Comments on this please? |
|
@reinux : I am still thinking of a better self-explainable API, I don't think a tuple of 3 with same types is best. Even though the ordering (previous,match,next) is likely the most natural one here. Just to show another proposal, I have tried to DU-model the outcomes, but I do not think it is any better to your proposal here. The number of possible combinations is an inherent part of binary search if we want this to be a primitive supporting all sorts of scenarios. |
|
I like the functionality and the API. |
The more I think about it, the more I'm liking
As for the return type, I think the only option we haven't explored yet is a single-case union with named parameters: type MapSearchResult<'k, 'v> =
MapSearchResult of left: ('k, 'v) option * exact: ('k, 'v) option * right: ('k, 'v) optionThis would effectively be the same as the tuple version, except that we'd be trading conciseness with some IDE assistance. I'm likewise unsure whether this is the best approach either. |
|
From the options so far, this API seems the best for avoiding errors and for communicating intent clearly. type MapSearchResult<'k, 'v> =
MapSearchResult of left: ('k, 'v) option * exact: ('k, 'v) option * right: ('k, 'v) option
|
|
The |
|
There are more benefits to a custom type over tuples for API contracts:
|
|
@T-Gro A binary breaking change would still occur when adding another field to The point about older compilers and IDE tools may apply but documentation would help - we can't be stuck in the past with API additions. Also, are extensions really a point of concern? What are the use cases for extending MapSearchResult at all, as opposed to using a function for it? |
|
T-Gro
left a comment
There was a problem hiding this comment.
See #734 (comment) for the last changes to incorporate.
After that is done, this PR can be merged.
|
@reinux : Are you interested in pursuing the RFC and related impl further? |
|
I hope to get back to it soon! Swamped with multiple projects at the moment but I'll keep this tab open. |
Rendered RFC