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

Open-ended ranges and rangeUntil operator #314

Open
ilya-g opened this issue Jul 22, 2022 · 1 comment
Open

Open-ended ranges and rangeUntil operator #314

ilya-g opened this issue Jul 22, 2022 · 1 comment

Comments

@ilya-g
Copy link
Member

ilya-g commented Jul 22, 2022

This issue is for discussion of the proposal to introduce rangeUntil (..<) operator in Kotlin and the corresponding types for open-ended ranges.

Proposal PR #315

@Whathecode
Copy link

Whathecode commented Jul 24, 2022

Thank you for this excellent overview of planned additions and tradeoffs considered!

I want to comment on the following:

Common supertype of ClosedRange and OpenEndRange
...
Introducing a more dedicated common supertype of the ClosedRange and OpenEndRange could help in this situation, however, it's unclear what useful operations such supertype would provide.

I'm the library author of kotlinx.interval, which approaches ranges using a common generic base type (including the possibility of a separate type parameter for range 'sizes'). To help assess whether or not such a base type may be useful, I will soon continue porting some of the existing C# implementation I did to Kotlin, and add example use cases.

In short, I remember using them in a generic binary sort algorithm, and operations on range collections. I.e., given a collection of time intervals, does a specified timestamp fall within any of the ranges, or what's the Duration covered by a set of Instant intervals? But, likely those could have been simple collections of closed ranges only. I don't recall fully whether mixing half-open and closed ranges was ever a true requirement for these use cases.

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