Packages

trait AsyncSeqIterator[F[_], I, A] extends AnyRef

Provides infinite and async computation results lazily iterating over some user defined function Unlike standard Stream[]/LazyList[] from Scala, this implementation doesn't memorise previous values. Unlike Future.sequence/fold we don't know beforehand how many async actions are coming

Async iterator implements:

- AsyncSeqIterator#foldLeft for accumulating batching results

- AsyncSeqIterator#map to transform batch results

- AsyncSeqIterator#foreach to iterate with effects

For example:

 case class MyItem( value: String, cursor: Option[Int] )

 def initialItem(): Future[MyItem] = Future.successful(
   MyItem( "initial", Some( 1 ) )
 )

 def nextItem( position: Int ): Future[MyItem] = {
   if (position < 10) {
     Future.successful(
       MyItem( "next", Some( position + 1 ) )
     )
   } else {
     Future.successful(
       MyItem( "last", None )
     )
   }
 }

 val iterator = AsyncSeqIterator.cons[Future,MyItem, String, Int](
   initial = initialItem(),
   toValue = _.value,
   getPos = _.cursor,
   producer = nextItem
 )

iterator
    .foldLeft( List[String]() ) {
       case ( all, itemValue ) =>
         all :+ itemValue
     }
F

async/effect monad kind (for example, standard scala.concurrent.Future or cats.effect.IO)

I

iterating over item type which has a some position

A

extracted value type (extracted from I)

Note

It is not possible to implement standard Iterator[] because of the sync nature of hasNext.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsyncSeqIterator
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def filter(f: (A) ⇒ Boolean): AsyncSeqIterator[F, I, A]

    Filter items using the given function f

    Filter items using the given function f

    f

    a filter function

    returns

    a new iterator with filtered items

  2. abstract def foldLeft[B](initial: B)(f: (B, A) ⇒ B): F[B]

    Iterate and fold (combining) values into the user specified structure and given function f

    Iterate and fold (combining) values into the user specified structure and given function f

    initial

    initial value

    f

    folding function

    returns

    a folded value

  3. abstract def foreach[U](f: (A) ⇒ U): Unit

    Apply the given function f to each element of this linear sequence (while respecting the order of the elements).

    Apply the given function f to each element of this linear sequence (while respecting the order of the elements).

    f

    a function to apply

  4. abstract def item(): F[I]

    Future of current item

  5. abstract def map[B](f: (A) ⇒ B): AsyncSeqIterator[F, I, B]

    Mapping value of items using the given function f

    Mapping value of items using the given function f

    f

    a mapping function

    returns

    a function result for value

  6. abstract def next(): F[Option[AsyncSeqIterator[F, I, A]]]

    Future next iterator if it exists (depends on current item and its position/state)

  7. abstract def value(): F[Option[A]]

    Future of value of item

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped