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

Add more introspection properties #1754

Closed
danieldietrich opened this Issue Dec 11, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@danieldietrich
Member

danieldietrich commented Dec 11, 2016

The bold printed properties are new:

Value has:

  • isAsync() — is computed asynchronously
  • isLazy() — is evaluated lazily (as opposed to eagerly)
  • isSingleValued() — can contain at most one value

Traversable additionally has:

  • hasDefiniteSize() — has at most a finite number of elements
  • isDistinct() — cannot contain duplicate elements (using equals)
  • isOrdered() — has an underlying Comparator (by implementing Ordered)
  • isSequential() — elements occur in a predictable, fixed sequence
  • isTraversableOnce() — can be iterated once (read: is stateful)

Note:** It is odd that these properties are observed on an instance of that type, for example:

// = false, but a user may think that is has size 1
Stream(1).hasDefiniteSize();

// = false, but a user may think that the list contains distinct elements
List(1, 2).isDistinct();

// = false, but a user may think that the elements are ordered in the list
List(1, 2).isOrdered();

// = false, but a user may think that there is only a single element
List(1).isSingleValued();

We need to keep in mind that these properties are intended to be observed on instances of super types, for example:

if (traversable.hasDefiniteSize()) {
    println("the size is: " + traversable.size());
}

if (traversable.isOrdered()) {
    Comparator<T> comparator = ((Ordered<T>) traversable).comparator();
    // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment