question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

much better return type for Iterable.sequence()

See original GitHub issue

Today, @jvasileff figured out the solution to a problem that has bugged us for years — how to assign the correct return type to Iterable.sequence() for known-nonempty streams.

The return type is:

[Element+] | []&Iterable<Element,Absent>

There would be one big problem with making this change, and one much smaller problem:

  1. It would involve a binary-incompatible change to the return type of Iterable.sequence(), which at the Java level would widen from Sequential<? extends Element> to Object.
  2. For the case of an empty stream, that is not something special like [], "", or {}, calling sequence() would result in a reified check of the type argument Absent.

Problem (1) is rather easy to fix with a little hack to the compiler backend to preserve the previous return type Sequential<? extends Element>.

Problem (2) is not so easy to fix, but may not be a big deal.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:27 (27 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Dec 7, 2016

That’s really nice!

Type functions FTW.

0reactions
xkr47commented, Feb 24, 2017

Amazing, great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i return Iterable with a Function? - Stack Overflow
Implement the Iterator interface by providing implementations for next() and hasNext() . hasNext() simply returns true or false if you have ...
Read more >
Incremental Transformation of an Iterable Sequence in Java
The main class implements the Iterable interface (an abstract factory of iterators). The factory method ( iterator() ) returns a new RIterator ,...
Read more >
Python Basics: Iteration, Iterables, Iterators, and Looping
An iterable is an object capable of returning its members one by one. Said in other words, ... Sequences are a very common...
Read more >
Should I return Iterable or Enumeration in Java
In order to achieve better immutability, should my API return java.lang.Iterable<T> or java.util.Enumeration<E> ? Since Iterable's iterator has a remove() ...
Read more >
Iterables - Python Like You Mean It
all : returns True only if bool(item) was True for all items in the iterable. max : return the largest value in an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found