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.
- Alphabetic
- By Inheritance
- AsyncSeqIterator
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
filter(f: (A) ⇒ Boolean): AsyncSeqIterator[F, I, A]
Filter items using the given function
fFilter items using the given function
f- f
a filter function
- returns
a new iterator with filtered items
-
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
fIterate and fold (combining) values into the user specified structure and given function
f- initial
initial value
- f
folding function
- returns
a folded value
-
abstract
def
foreach[U](f: (A) ⇒ U): Unit
Apply the given function
fto each element of this linear sequence (while respecting the order of the elements).Apply the given function
fto each element of this linear sequence (while respecting the order of the elements).- f
a function to apply
-
abstract
def
item(): F[I]
Future of current item
-
abstract
def
map[B](f: (A) ⇒ B): AsyncSeqIterator[F, I, B]
Mapping value of items using the given function
fMapping value of items using the given function
f- f
a mapping function
- returns
a function result for value
-
abstract
def
next(): F[Option[AsyncSeqIterator[F, I, A]]]
Future next iterator if it exists (depends on current item and its position/state)
-
abstract
def
value(): F[Option[A]]
Future of value of item
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()