Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 1.16 KB

File metadata and controls

35 lines (30 loc) · 1.16 KB

thankable-iterator

call thankU() before calling next()

use

an iterator over a Collection<E> that throws an UnthankedException if you don't call thankU() before calling next()

ThankableIterator<Integer> it = ThankableIterator.of(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
it.thankU()
  .next();

the static factory has a method to return a specific implementation based on the Teacher instance passed to it (see below)

teachers

love

ThankableIterator.of(underlying, Teachers.LOVE);

the default, because love should always be the default

patience

ThankableIterator.of(underlying, Teachers.PATIENCE);

if the underlying iterator is blocking, uses take() to block until the next element is available.

note that this technically breaks the contract of Iterator::next since Iterator instances are eventually-consistent views of the underlying Collection (i.e. a blocking next implementation is usually a bad thing)

pain

ThankableIterator.of(underlying, Teachers.PAIN);

throws an UnthankedException whenever you try to do anything, even thank it. typical.

acknowledgments

  • ariana grande
  • my exes