Class

monix.tail.Iterant

Suspend

Related Doc: package Iterant

Permalink

final case class Suspend[F[_], A](rest: F[Iterant[F, A]], stop: F[Unit]) extends Iterant[F, A] with Product with Serializable

Builds a stream state equivalent with Iterant.NextCursor.

The Suspend state of the Iterant represents a suspended stream to be evaluated in the F context. It is useful to delay the evaluation of a stream by deferring to F.

rest

is the next state in the sequence that will produce the rest of the stream when evaluated

stop

is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)

Linear Supertypes
Iterant[F, A], Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Suspend
  2. Iterant
  3. Serializable
  4. Serializable
  5. Product
  6. Equals
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Suspend(rest: F[Iterant[F, A]], stop: F[Unit])

    Permalink

    rest

    is the next state in the sequence that will produce the rest of the stream when evaluated

    stop

    is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ++[B >: A](rhs: F[Iterant[F, B]])(implicit F: Applicative[F]): Iterant[F, B]

    Permalink

    Appends a stream to the end of the source, effectively concatenating them.

    Appends a stream to the end of the source, effectively concatenating them.

    The right hand side is suspended in the F[_] data type, thus allowing for laziness.

    Example:

    // Yields 1, 2, 3, 4
    Iterant[Task].of(1, 2) ++ Task.suspend {
      Iterant[Task].of(3, 4)
    }
    rhs

    is the iterant to append at the end of our source.

    Definition Classes
    Iterant
  4. final def ++[B >: A](rhs: Iterant[F, B])(implicit F: Applicative[F]): Iterant[F, B]

    Permalink

    Appends the given stream to the end of the source, effectively concatenating them.

    Appends the given stream to the end of the source, effectively concatenating them.

    Example:

    // Yields 1, 2, 3, 4
    Iterant[Task].of(1, 2) ++ Iterant[Task].of(3, 4)
    rhs

    is the (right hand side) iterant to concatenate at the end of this iterant.

    Definition Classes
    Iterant
  5. final def +:[B >: A](head: B)(implicit F: Applicative[F]): Iterant[F, B]

    Permalink

    Prepends an element to the iterant, returning a new iterant that will start with the given head and then continue with the source.

    Prepends an element to the iterant, returning a new iterant that will start with the given head and then continue with the source.

    Example:

    // Yields 1, 2, 3, 4
    1 +: Iterant[Task].of(2, 3, 4)
    head

    is the element to prepend at the start of this iterant

    Definition Classes
    Iterant
  6. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def attempt(implicit F: Sync[F]): Iterant[F, Either[Throwable, A]]

    Permalink

    Converts the source Iterant that emits A elements into an iterant that emits Either[Throwable, A], thus materializing whatever error that might interrupt the stream.

    Converts the source Iterant that emits A elements into an iterant that emits Either[Throwable, A], thus materializing whatever error that might interrupt the stream.

    Example:

    // Yields Right(1), Right(2), Right(3)
    Iterant[Task].of(1, 2, 3).attempt
    
    
    // Yields Right(1), Right(2), Left(DummyException())
    (Iterant[Task].of(1, 2) ++
      Iterant[Task].raiseError(DummyException())).attempt
    Definition Classes
    Iterant
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def collect[B](pf: PartialFunction[A, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Builds a new iterant by applying a partial function to all elements of the source on which the function is defined.

    Builds a new iterant by applying a partial function to all elements of the source on which the function is defined.

    Example:

    // Yields 2, 4, 6
    Iterant[Task].of(1, 2, 3, 4, 5, 6)
      .map { x => Option(x).filter(_ % 2 == 0) }
      .collect { case Some(x) => x }
    B

    the element type of the returned iterant.

    pf

    the partial function that filters and maps the iterant

    returns

    a new iterant resulting from applying the partial function pf to each element on which it is defined and collecting the results. The order of the elements is preserved.

    Definition Classes
    Iterant
  11. final def completeL(implicit F: Sync[F]): F[Unit]

    Permalink

    Upon evaluation of the result, consumes this iterant to completion.

    Upon evaluation of the result, consumes this iterant to completion.

    Example:

    val onFinish: Task[Unit] =
      iterant.completeL >> Task.eval(println("Done!"))
    Definition Classes
    Iterant
  12. final def concat[B](implicit ev: <:<[A, Iterant[F, B]], F: Sync[F]): Iterant[F, B]

    Permalink

    Alias for concat.

    Alias for concat.

    Definition Classes
    Iterant
  13. final def concatMap[B](f: (A) ⇒ Iterant[F, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Alias for flatMap.

    Alias for flatMap.

    Definition Classes
    Iterant
  14. final def doOnEarlyStop(f: F[Unit])(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Given a routine make sure to execute it whenever the consumer executes the current stop action.

    Given a routine make sure to execute it whenever the consumer executes the current stop action.

    Example:

    iterant.doOnEarlyStop(Task.eval {
      println("Was stopped early!")
    })
    f

    is the function to execute on early stop

    Definition Classes
    Iterant
  15. final def doOnFinish(f: (Option[Throwable]) ⇒ F[Unit])(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Returns a new enumerator in which f is scheduled to be executed on halt or on earlyStop.

    Returns a new enumerator in which f is scheduled to be executed on halt or on earlyStop.

    This would typically be used to release any resources acquired by this enumerator.

    Note that doOnEarlyStop is subsumed under this operation, the given f being evaluated on both reaching the end or canceling early.

    Example:

    iterant.doOnEarlyStop(err => Task.eval {
      err match {
        case Some(e) => log.error(e)
        case None =>
          println("Was consumed successfully!")
      }
    })
    f

    is the function to execute on early stop

    Definition Classes
    Iterant
  16. final def drop(n: Int)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Drops the first n elements (from the start).

    Drops the first n elements (from the start).

    Example:

    // Yields 4, 5
    Iterant[Task].of(1, 2, 3, 4, 5).drop(3)
    n

    the number of elements to drop

    returns

    a new iterant that drops the first n elements emitted by the source

    Definition Classes
    Iterant
  17. final def dropWhile(p: (A) ⇒ Boolean)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Drops the longest prefix of elements that satisfy the given predicate and returns a new iterant that emits the rest.

    Drops the longest prefix of elements that satisfy the given predicate and returns a new iterant that emits the rest.

    Example:

    // Yields 4, 5
    Iterant[Task].of(1, 2, 3, 4, 5).dropWhile(_ < 4)
    p

    is the predicate used to test whether the current element should be dropped, if true, or to interrupt the dropping process, if false

    returns

    a new iterant that drops the elements of the source until the first time the given predicate returns false

    Definition Classes
    Iterant
  18. def earlyStop(implicit F: Applicative[F]): F[Unit]

    Permalink

    Returns a computation that should be evaluated in case the streaming must stop before reaching the end.

    Returns a computation that should be evaluated in case the streaming must stop before reaching the end.

    This is useful to release any acquired resources, like opened file handles or network sockets.

    Definition Classes
    SuspendIterant
  19. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  20. final def filter(p: (A) ⇒ Boolean)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Filters the iterant by the given predicate function, returning only those elements that match.

    Filters the iterant by the given predicate function, returning only those elements that match.

    Example:

    // Yields 2, 4, 6
    Iterant[Task].of(1, 2, 3, 4, 5, 6).filter(_ % 2 == 0)
    p

    the predicate used to test elements.

    returns

    a new iterant consisting of all elements that satisfy the given predicate. The order of the elements is preserved.

    Definition Classes
    Iterant
  21. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. final def flatMap[B](f: (A) ⇒ Iterant[F, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Applies the function to the elements of the source and concatenates the results.

    Applies the function to the elements of the source and concatenates the results.

    This operation is the monadic "bind", with all laws it entails.

    Also note that the implementation can use constant memory depending on usage, thus it can be used in tail recursive loops.

    Example:

    // Effectively equivalent with .filter
    Iterant[Task].of(1, 2, 3, 4, 5, 6).flatMap { elem =>
      if (elem % 2 == 0)
        Iterant[Task].pure(elem)
      else
        Iterant[Task].empty
    }
    f

    is the function mapping elements from the source to iterants

    Definition Classes
    Iterant
  23. final def flatten[B](implicit ev: <:<[A, Iterant[F, B]], F: Sync[F]): Iterant[F, B]

    Permalink

    Given an Iterant that generates Iterant elements, concatenates all the generated iterants.

    Given an Iterant that generates Iterant elements, concatenates all the generated iterants.

    Equivalent with: source.flatMap(x => x)

    Definition Classes
    Iterant
  24. final def foldLeftL[S](seed: ⇒ S)(op: (S, A) ⇒ S)(implicit F: Sync[F]): F[S]

    Permalink

    Left associative fold using the function f.

    Left associative fold using the function f.

    On execution the stream will be traversed from left to right, and the given function will be called with the prior result, accumulating state until the end, when the summary is returned.

    Example:

    // Yields 15 (1 + 2 + 3 + 4 + 5)
    Iterant[Task].of(1, 2, 3, 4, 5).foldLeftL(0)(_ + _)
    seed

    is the start value

    op

    is the binary operator

    returns

    the result of inserting op between consecutive elements of this iterant, going from left to right with the seed as the start value, or seed if the iterant is empty.

    Definition Classes
    Iterant
  25. final def foreach(cb: (A) ⇒ Unit)(implicit F: Sync[F]): F[Unit]

    Permalink

    Consumes the source iterable, executing the given callback for each element.

    Consumes the source iterable, executing the given callback for each element.

    Example:

    // Prints all elements, each one on a different line
    Iterant[Task].of(1, 2, 3).foreachL { elem =>
      println("Elem: " + elem.toString)
    }
    cb

    is the callback to call for each element emitted by the source.

    Definition Classes
    Iterant
  26. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  27. final def headOptionL(implicit F: Sync[F]): F[Option[A]]

    Permalink

    Optionally selects the first element.

    Optionally selects the first element.

    // Yields Some(1)
    Iterant[Task].of(1, 2, 3, 4).headOptionL
    
    // Yields None
    Iterant[Task].empty[Int].headOptionL
    returns

    the first element of this iterant if it is nonempty, or None if it is empty, in the F context.

    Definition Classes
    Iterant
  28. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  29. final def map[B](f: (A) ⇒ B)(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Returns a new stream by mapping the supplied function over the elements of the source.

    Returns a new stream by mapping the supplied function over the elements of the source.

    // Yields 2, 4, 6
    Iterant[Task].of(1, 2, 3).map(_ * 2)
    f

    is the mapping function that transforms the source

    returns

    a new iterant that's the result of mapping the given function over the source

    Definition Classes
    Iterant
  30. final def mapEval[B](f: (A) ⇒ F[B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Given a mapping function that returns a possibly lazy or asynchronous result, applies it over the elements emitted by the stream.

    Given a mapping function that returns a possibly lazy or asynchronous result, applies it over the elements emitted by the stream.

    Iterant[Task].of(1, 2, 3, 4).mapEval { elem =>
      Task.eval {
        println("Received: " + elem.toString)
        elem * 2
      }
    }
    f

    is the mapping function that transforms the source

    returns

    a new iterant that's the result of mapping the given function over the source,

    Definition Classes
    Iterant
  31. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  32. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  33. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  34. final def onErrorHandle[B >: A](f: (Throwable) ⇒ B)(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events fallbacks to an iterant emitting a single element generated by the backup function.

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events fallbacks to an iterant emitting a single element generated by the backup function.

    Example:

    val prefix = Iterant[Task].of(1, 2, 3, 4)
    val suffix = Iterant[Task].raiseError(DummyException("dummy"))
    val fa = prefix ++ suffix
    
    fa.onErrorHandle { _ => 5 }

    See onErrorRecover for the version that takes a partial function as a parameter.

    f

    is a function that matches errors with a backup element that is emitted when the source throws an error.

    Definition Classes
    Iterant
  35. final def onErrorHandleWith[B >: A](f: (Throwable) ⇒ Iterant[F, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events continues with the specified backup sequence generated by the given function.

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events continues with the specified backup sequence generated by the given function.

    Example:

    val prefix = Iterant[Task].of(1, 2, 3, 4)
    val suffix = Iterant[Task].raiseError(DummyException("dummy"))
    val fa = prefix ++ suffix
    
    fa.onErrorHandleWith {
      case _: DummyException =>
        Iterant[Task].pure(5)
      case other =>
        Iterant[Task].raiseError(other)
    }

    See onErrorRecoverWith for the version that takes a partial function as a parameter.

    f

    is a function that matches errors with a backup throwable that is subscribed when the source throws an error.

    Definition Classes
    Iterant
  36. final def onErrorIgnore(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Returns a new Iterant that mirrors the source, but ignores any errors in case they happen.

    Returns a new Iterant that mirrors the source, but ignores any errors in case they happen.

    Definition Classes
    Iterant
  37. final def onErrorRecover[B >: A](pf: PartialFunction[Throwable, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events fallbacks to an iterant emitting a single element generated by the backup function.

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events fallbacks to an iterant emitting a single element generated by the backup function.

    The created Iterant mirrors the behavior of the source in case the source does not end with an error or if the thrown Throwable is not matched.

    Example:

    val prefix = Iterant[Task].of(1, 2, 3, 4)
    val suffix = Iterant[Task].raiseError(DummyException("dummy"))
    val fa = prefix ++ suffix
    
    fa.onErrorRecover {
      case _: DummyException => 5
    }

    See onErrorHandle for the version that takes a total function as a parameter.

    pf

    - a function that matches errors with a backup element that is emitted when the source throws an error.

    Definition Classes
    Iterant
  38. final def onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Iterant[F, B]])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events continues with the specified backup sequence generated by the given partial function.

    Returns an Iterant that mirrors the behavior of the source, unless the source is terminated with an error, in which case the streaming of events continues with the specified backup sequence generated by the given partial function.

    The created Iterant mirrors the behavior of the source in case the source does not end with an error or if the thrown Throwable is not matched.

    Example:

    val prefix = Iterant[Task].of(1, 2, 3, 4)
    val suffix = Iterant[Task].raiseError(DummyException("dummy"))
    val fa = prefix ++ suffix
    
    fa.onErrorRecoverWith {
      case _: DummyException =>
        Iterant[Task].pure(5)
    }

    See onErrorHandleWith for the version that takes a total function as a parameter.

    pf

    is a function that matches errors with a backup throwable that is subscribed when the source throws an error.

    Definition Classes
    Iterant
  39. val rest: F[Iterant[F, A]]

    Permalink

    is the next state in the sequence that will produce the rest of the stream when evaluated

  40. final def skipSuspendL(implicit F: Sync[F]): F[Iterant[F, A]]

    Permalink

    Skips over Iterant.Suspend states, along with Iterant.NextCursor and Iterant.NextBatch states that signal empty collections.

    Skips over Iterant.Suspend states, along with Iterant.NextCursor and Iterant.NextBatch states that signal empty collections.

    Will mirror the source, except that the emitted internal states might be different. Can be used as an optimization if necessary.

    Definition Classes
    Iterant
  41. val stop: F[Unit]

    Permalink

    is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g.

    is a computation to be executed in case streaming is stopped prematurely, giving it a chance to do resource cleanup (e.g. close file handles)

  42. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  43. final def tail(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Drops the first element of the source iterant, emitting the rest.

    Drops the first element of the source iterant, emitting the rest.

    Example:

    // Yields 2, 3, 4
    Iterant[Task].of(1, 2, 3, 4).tail
    returns

    a new iterant that upon evaluation will emit all elements of the source, except for the head

    Definition Classes
    Iterant
  44. final def take(n: Int)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Creates a new iterant that upon evaluation will select the first n elements from the source and then stop, in the order they are emitted by the source.

    Creates a new iterant that upon evaluation will select the first n elements from the source and then stop, in the order they are emitted by the source.

    Example:

    // Yields 1, 2, 3
    Iterant[Task].of(1, 2, 3, 4, 5, 6).take(3)
    n

    is the number of elements to take from this iterant

    returns

    a new iterant instance that on evaluation will emit only the first n elements of this iterant

    Definition Classes
    Iterant
  45. final def takeLast(n: Int)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Creates a new iterable that only emits the last n elements emitted by the source.

    Creates a new iterable that only emits the last n elements emitted by the source.

    In case the source triggers an error, then the underlying buffer gets dropped and the error gets emitted immediately.

    Example:

    // Yields 1, 2, 3
    Iterant[Task].of(1, 2, 3, 4, 5, 6).take(3)
    n

    is the number of elements to take from the end of the stream.

    returns

    a new iterant instance that on evaluation will emit the last n elements of the source

    Definition Classes
    Iterant
  46. final def takeWhile(p: (A) ⇒ Boolean)(implicit F: Sync[F]): Iterant[F, A]

    Permalink

    Takes longest prefix of elements that satisfy the given predicate and returns a new iterant that emits those elements.

    Takes longest prefix of elements that satisfy the given predicate and returns a new iterant that emits those elements.

    Example:

    // Yields 1, 2, 3
    Iterant[Task].of(1, 2, 3, 4, 5, 6).takeWhile(_ < 4)
    p

    is the function that tests each element, stopping the streaming on the first false result

    returns

    a new iterant instance that on evaluation will all elements of the source for as long as the given predicate returns true, stopping upon the first false result

    Definition Classes
    Iterant
  47. final def toListL(implicit F: Sync[F]): F[List[A]]

    Permalink

    Aggregates all elements in a List and preserves order.

    Aggregates all elements in a List and preserves order.

    Example:

    // Yields List(1, 2, 3, 4)
    Iterant[Task].of(1, 2, 3, 4).toListL

    Note that this operation is dangerous, since if the iterant is infinite then this operation is non-terminating, the process probably blowing up with an out of memory error sooner or later.

    Definition Classes
    Iterant
  48. final def unsafeFlatMap[B](f: (A) ⇒ Iterant[F, B])(implicit F: Sync[F]): Iterant[F, B]

    Permalink

    Applies the function to the elements of the source and concatenates the results.

    Applies the function to the elements of the source and concatenates the results.

    This variant of flatMap is not referentially transparent, because it tries to apply function f immediately, in case the Iterant is in a NextCursor or NextBatch state.

    To be used for optimizations, but keep in mind it's unsafe, as its application isn't referentially transparent.

    f

    is the function mapping elements from the source to iterants

    Definition Classes
    Iterant
  49. final def upcast[B >: A]: Iterant[F, B]

    Permalink

    Explicit covariance operator.

    Explicit covariance operator.

    The Iterant type isn't covariant in type param A, because covariance doesn't play well with a higher-kinded type like F[_]. So in case you have an Iterant[F, A], but need an Iterant[F, B], knowing that A extends B, then you can do an upcast.

    Example:

    val source: Iterant[Task, List[Int]] = ???
    
    // This will trigger an error because of the invariance:
    val sequences: Iterant[Task, Seq[Int]] = source
    
    // But this will work just fine:
    val sequences: Iterant[Task, Seq[Int]] = source.upcast[Seq[Int]]
    Definition Classes
    Iterant
  50. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  52. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  53. final def zip[B](rhs: Iterant[F, B])(implicit F: Sync[F]): Iterant[F, (A, B)]

    Permalink

    Lazily zip two iterants together.

    Lazily zip two iterants together.

    The length of the result will be the shorter of the two arguments.

    Example:

    val lh = Iterant[Task].of(11, 12, 13, 14)
    val rh = Iterant[Task].of(21, 22, 23, 24, 25)
    
    // Yields (11, 21), (12, 22), (13, 23), (14, 24)
    lh.zip(rh)
    rhs

    is the other iterant to zip the source with (the right hand side)

    Definition Classes
    Iterant
  54. final def zipMap[B, C](rhs: Iterant[F, B])(f: (A, B) ⇒ C)(implicit F: Sync[F]): Iterant[F, C]

    Permalink

    Lazily zip two iterants together, using the given function f to produce output values.

    Lazily zip two iterants together, using the given function f to produce output values.

    The length of the result will be the shorter of the two arguments.

    Example:

    val lh = Iterant[Task].of(11, 12, 13, 14)
    val rh = Iterant[Task].of(21, 22, 23, 24, 25)
    
    // Yields 32, 34, 36, 38
    lh.zipMap(rh) { (a, b) => a + b }
    rhs

    is the other iterant to zip the source with (the right hand side)

    f

    is the mapping function to transform the zipped (A, B) elements

    Definition Classes
    Iterant

Inherited from Iterant[F, A]

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped