final class Force[+O, +R] extends AnyVal
Operations on a Segment
which force evaluation of some part or all of a segments elements.
- Source
- Segment.scala
- Alphabetic
- By Inheritance
- Force
- AnyVal
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
- def +(other: String): String
- def ->[B](y: B): (Force[O, R], B)
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
drop(n: Long): Either[(R, Long), Segment[O, R]]
Eagerly drops
n
elements from the head of this segment, returning either the result and the number of elements remaining to drop, if the end of the segment was reached, or a new segment, if the end of the segment was not reached.Eagerly drops
n
elements from the head of this segment, returning either the result and the number of elements remaining to drop, if the end of the segment was reached, or a new segment, if the end of the segment was not reached.scala> Segment(1,2,3,4,5).force.drop(3).toOption.get.force.toVector res0: Vector[Int] = Vector(4, 5) scala> Segment(1,2,3,4,5).force.drop(7) res1: Either[(Unit, Long),Segment[Int,Unit]] = Left(((),2))
Example: -
final
def
dropWhile(p: (O) ⇒ Boolean, dropFailure: Boolean = false): Either[R, Segment[O, R]]
Eagerly drops elements from the head of this segment until the supplied predicate returns false, returning either the result, if the end of the segment was reached without the predicate failing, or the remaining segment.
Eagerly drops elements from the head of this segment until the supplied predicate returns false, returning either the result, if the end of the segment was reached without the predicate failing, or the remaining segment.
If
dropFailure
is true, the first element that failed the predicate will be dropped. If false, the first element that failed the predicate will be the first element of the remainder.scala> Segment(1,2,3,4,5).force.dropWhile(_ < 3).map(_.force.toVector) res0: Either[Unit,Vector[Int]] = Right(Vector(3, 4, 5)) scala> Segment(1,2,3,4,5).force.dropWhile(_ < 10) res1: Either[Unit,Segment[Int,Unit]] = Left(())
Example: - def ensuring(cond: (Force[O, R]) ⇒ Boolean, msg: ⇒ Any): Force[O, R]
- def ensuring(cond: (Force[O, R]) ⇒ Boolean): Force[O, R]
- def ensuring(cond: Boolean, msg: ⇒ Any): Force[O, R]
- def ensuring(cond: Boolean): Force[O, R]
-
def
foreach(f: (O) ⇒ Unit): R
Invokes
f
on each output of this segment.Invokes
f
on each output of this segment.scala> val buf = collection.mutable.ListBuffer[Int]() scala> Segment(1,2,3).cons(0).force.foreach(i => buf += i) res0: Unit = () scala> buf.toList res1: List[Int] = List(0, 1, 2, 3)
Example: -
def
foreachChunk(f: (Chunk[O]) ⇒ Unit): R
Invokes
f
on each chunk of this segment.Invokes
f
on each chunk of this segment.scala> val buf = collection.mutable.ListBuffer[Chunk[Int]]() scala> Segment(1,2,3).cons(0).force.foreachChunk(c => buf += c) res0: Unit = () scala> buf.toList res1: List[Chunk[Int]] = List(Chunk(0), Chunk(1, 2, 3))
Example: - def formatted(fmtstr: String): String
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
run(implicit ev: <:<[O, Nothing]): R
Computes the result of this segment.
Computes the result of this segment. May only be called when
O
isNothing
, to prevent accidentally ignoring output values. To intentionally ignore outputs, calls.drain.force.run
.scala> Segment(1, 2, 3).withSize.drain.force.run res0: (Unit,Long) = ((),3)
Example: -
final
def
splitAt(n: Long, maxSteps: Option[Long] = None): Either[(R, Catenable[Chunk[O]], Long), (Catenable[Chunk[O]], Segment[O, R])]
Splits this segment at the specified index by simultaneously taking and dropping.
Splits this segment at the specified index by simultaneously taking and dropping.
If the segment has less than
n
elements, a left is returned, providing the result of the segment, all sub-segments taken, and the remaining number of elements (i.e., size - n).If the segment has more than
n
elements, a right is returned, providing the sub-segments up to then
-th element and a remainder segment.The prefix is computed eagerly while the suffix is computed lazily.
The
maxSteps
parameter provides a notion of fairness. If specified, steps through the staged machine are counted while executing and if the limit is reached, execution completes, returning aRight
consisting of whatever elements were seen in the firstmaxSteps
steps. This provides fairness but yielding the computation back to the caller but with less thann
accumulated values.scala> Segment(1, 2, 3, 4, 5).force.splitAt(2) res0: Either[(Unit,Catenable[Chunk[Int]],Long),(Catenable[Chunk[Int]],Segment[Int,Unit])] = Right((Catenable(Chunk(1, 2)),Chunk(3, 4, 5))) scala> Segment(1, 2, 3, 4, 5).force.splitAt(7) res0: Either[(Unit,Catenable[Chunk[Int]],Long),(Catenable[Chunk[Int]],Segment[Int,Unit])] = Left(((),Catenable(Chunk(1, 2, 3, 4, 5)),2))
Example: -
final
def
splitWhile(p: (O) ⇒ Boolean, emitFailure: Boolean = false): Either[(R, Catenable[Chunk[O]]), (Catenable[Chunk[O]], Segment[O, R])]
Splits this segment at the first element where the supplied predicate returns false.
Splits this segment at the first element where the supplied predicate returns false.
Analagous to siumultaneously running
takeWhile
anddropWhile
.If
emitFailure
is false, the first element which fails the predicate is returned in the suffix segment. If true, it is returned as the last element in the prefix segment.If the end of the segment is reached and the predicate has not failed, a left is returned, providing the segment result and the catenated sub-segments. Otherwise, a right is returned, providing the prefix sub-segments and the suffix remainder.
scala> Segment(1, 2, 3, 4, 5).force.splitWhile(_ != 3) res0: Either[(Unit,Catenable[Chunk[Int]]),(Catenable[Chunk[Int]],Segment[Int,Unit])] = Right((Catenable(Chunk(1, 2)),Chunk(3, 4, 5))) scala> Segment(1, 2, 3, 4, 5).force.splitWhile(_ != 7) res0: Either[(Unit,Catenable[Chunk[Int]]),(Catenable[Chunk[Int]],Segment[Int,Unit])] = Left(((),Catenable(Chunk(1, 2, 3, 4, 5))))
Example: -
def
toArray[O2 >: O](implicit ct: ClassTag[O2]): Array[O2]
Converts this segment to an array, discarding the result.
Converts this segment to an array, discarding the result.
Caution: calling
toArray
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toArray res0: Array[Int] = Array(-1, 0, 1, 2, 3)
Example: -
def
toCatenable: Catenable[O]
Converts this segment to a catenable of output values, discarding the result.
Converts this segment to a catenable of output values, discarding the result.
Caution: calling
toCatenable
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toCatenable.toList res0: List[Int] = List(-1, 0, 1, 2, 3)
Example: -
def
toChunk: Chunk[O]
Converts this segment to a single chunk, discarding the result.
Converts this segment to a single chunk, discarding the result.
Caution: calling
toChunk
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toChunk res0: Chunk[Int] = Chunk(-1, 0, 1, 2, 3)
Example: -
def
toChunks: Catenable[Chunk[O]]
Converts this segment to a sequence of chunks, discarding the result.
Converts this segment to a sequence of chunks, discarding the result.
Caution: calling
toChunks
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toChunks.toList res0: List[Chunk[Int]] = List(Chunk(-1), Chunk(0), Chunk(1, 2, 3))
Example: -
def
toList: List[O]
Converts this chunk to a list, discarding the result.
Converts this chunk to a list, discarding the result.
Caution: calling
toList
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toList res0: List[Int] = List(-1, 0, 1, 2, 3)
Example: -
def
toString(): String
- Definition Classes
- Any
-
def
toVector: Vector[O]
Converts this segment to a vector, discarding the result.
Converts this segment to a vector, discarding the result.
Caution: calling
toVector
on an infinite sequence will not terminate.scala> Segment(1, 2, 3).cons(0).cons(-1).force.toVector res0: Vector[Int] = Vector(-1, 0, 1, 2, 3)
Example: -
final
def
uncons: Either[R, (Segment[O, Unit], Segment[O, R])]
Returns the first output sub-segment of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.Returns the first output sub-segment of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.scala> Segment(1, 2, 3).cons(0).force.uncons res0: Either[Unit,(Segment[Int,Unit], Segment[Int,Unit])] = Right((Chunk(0),Chunk(1, 2, 3))) scala> Segment.empty[Int].force.uncons res1: Either[Unit,(Segment[Int,Unit], Segment[Int,Unit])] = Left(())
Example: -
final
def
uncons1: Either[R, (O, Segment[O, R])]
Returns the first output of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.Returns the first output of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.- Annotations
- @tailrec()
scala> Segment(1, 2, 3).cons(0).force.uncons1 res0: Either[Unit,(Int, Segment[Int,Unit])] = Right((0,Chunk(1, 2, 3))) scala> Segment.empty[Int].force.uncons1 res1: Either[Unit,(Int, Segment[Int,Unit])] = Left(())
Example: -
final
def
unconsAll: (Catenable[Chunk[O]], R)
Returns all output chunks and the result of this segment after stepping it to completion.
Returns all output chunks and the result of this segment after stepping it to completion.
Will not terminate if run on an infinite segment.
scala> Segment(1, 2, 3).prepend(Segment(-1, 0)).force.unconsAll res0: (Catenable[Chunk[Int]], Unit) = (Catenable(Chunk(-1, 0), Chunk(1, 2, 3)),())
Example: -
final
def
unconsChunk: Either[R, (Chunk[O], Segment[O, R])]
Returns the first output chunk of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.Returns the first output chunk of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.scala> Segment(1, 2, 3).prepend(Segment(-1, 0)).force.unconsChunk res0: Either[Unit,(Chunk[Int], Segment[Int,Unit])] = Right((Chunk(-1, 0),Chunk(1, 2, 3))) scala> Segment.empty[Int].force.unconsChunk res1: Either[Unit,(Chunk[Int], Segment[Int,Unit])] = Left(())
Example: -
final
def
unconsChunks: Either[R, (Catenable[Chunk[O]], Segment[O, R])]
Returns the first output chunks of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.Returns the first output chunks of this segment along with the remainder, wrapped in
Right
, or if this segment is empty, returns the result wrapped inLeft
.Differs from
unconsChunk
when a single step results in multiple outputs.scala> Segment(1, 2, 3).prepend(Segment(-1, 0)).force.unconsChunks res0: Either[Unit,(Catenable[Chunk[Int]], Segment[Int,Unit])] = Right((Catenable(Chunk(-1, 0)),Chunk(1, 2, 3))) scala> Segment.empty[Int].force.unconsChunks res1: Either[Unit,(Catenable[Chunk[Int]], Segment[Int,Unit])] = Left(())
Example: - def →[B](y: B): (Force[O, R], B)