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

[enhancement] Add function is_singleton #8

Closed
gfitas opened this issue Dec 11, 2018 · 4 comments
Closed

[enhancement] Add function is_singleton #8

gfitas opened this issue Dec 11, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@gfitas
Copy link

gfitas commented Dec 11, 2018

Hello,

I was wondering if it will be possible to add a function that could say if an interval is a singleton or not ?
For the moment I just did i.lower==i.upper but I found it dirty. A solution with a function is_singleton will be more elegant.

Thank you in advance

@AlexandreDecan AlexandreDecan added the enhancement New feature or request label Dec 11, 2018
@AlexandreDecan
Copy link
Owner

Hello,

That's feasible ;) I've two questions in mind then:

  1. Shouldn't we also add is_left_open, is_right_open, is_left_closed, is_right_closed, is_left_bounded, is_right_bounded so we have a "full" set of property checkers?
  2. Should we add them as functions, or as methods (e.g. like i.is_empty). The latter seems more adequate...

@AlexandreDecan
Copy link
Owner

AlexandreDecan commented Dec 11, 2018

I'm currently considering making lower, left, right and upper available on Interval instances as well. As such, it won't be required to access the underlying AtomicInterval instances of an Interval instance to perform some common checks:

>>> x = I.openclosed(-I.inf, 0)
>>> # Check for left/right closed
>>> x.left == I.CLOSED, x.right == I.CLOSED
(False, True)
>>> # Check if interval is left/right bounded
>>> x.lower == -I.inf, x.upper == I.inf
(True, False)
>>> # Check for singleton
>>> x.lower == x.upper
False

@AlexandreDecan
Copy link
Owner

Does the change solve your problem? It allows you to do i.lower == i.upper instead of i.to_atomic().lower == i.to_atomic().upper or even i[0].lower == i[-1].upper.

I know that you found i.lower == i.upper "ugly", but it is the (second) most obvious piece of code to check for a singleton (the first one being is_singleton, but I don't think it really adds value to the library). I'm waiting for your feedback before pushing the changes.

@AlexandreDecan
Copy link
Owner

I merged the changes to master, among other (many) changes that should ease intervals transformations and modifications.

I'll release 1.8.0 tomorrow unless these changes do not solve this issue.

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

No branches or pull requests

2 participants