Class/Object

com.twitter.algebird

Scan

Related Docs: object Scan | package algebird

Permalink

sealed abstract class Scan[-I, +O] extends Serializable

The Scan trait is an alternative to the scanLeft method on iterators/other collections for a range of of use-cases where scanLeft is awkward to use. At a high level it provides some of the same functionality as scanLeft, but with a separation of "what is the state of the scan" from "what are the elements that I'm scanning over?". In particular, when scanning over an iterator with N elements, the output is an iterator with N elements (in contrast to scanLeft's N+1).

If you find yourself writing a scanLeft over pairs of elements, where you only use one element of the pair within the scanLeft, then throw that element away in a map immediately after the scanLeft is done, then this abstraction is for you.

The canonical method to use a scan is apply.

I

The type of elements that the computation is scanning over.

O

The output type of the scan (typically distinct from the hidden State of the scan).

Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Scan
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type State

    Permalink

    The computation of any given scan involves keeping track of a hidden state.

Abstract Value Members

  1. abstract def initialState: State

    Permalink

    The state of the scan before any elements have been processed

  2. abstract def presentAndNextState(i: I, stateBeforeProcessingI: State): (O, State)

    Permalink

    i

    An element in the stream to process

    stateBeforeProcessingI

    The state of the scan before processing i

    returns

    The output of the scan corresponding to processing i with state stateBeforeProcessing, along with the result of updating stateBeforeProcessing with the information from i.

Concrete 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 ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def andThenPresent[O1](g: (O) ⇒ O1): Aux[I, State, O1]

    Permalink
  5. def apply[In <: TraversableOnce[I], Out](inputs: In)(implicit bf: BuildFrom[In, O, Out]): Out

    Permalink

    In

    The type of the input collection

    Out

    The type of the output collection

    returns

    Given inputs as a collection of the form [a_1, ..., a_n] the output will be a collection of the form: [o_1, ..., o_n] where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i) and state_0 = initialState.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def compose[P](scan2: Scan[O, P]): Aux[I, (State, State), P]

    Permalink

    Takes the output of this scan and feeds as input into scan2.

    Takes the output of this scan and feeds as input into scan2.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], and scan2.apply([o_1, ..., o_n] = [p_1, ..., p_n] then compose will return a scan which returns [p_1, ..., p_n].

  9. def composePrepare[I1](f: (I1) ⇒ I): Aux[I1, State, O]

    Permalink
  10. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. def join[I2 <: I, O2](scan2: Scan[I2, O2]): Aux[I2, (State, State), (O, O2)]

    Permalink

    Given a scan that takes compatible input to this one, pairwise compose the state and outputs of each scan on a common input stream.

    Given a scan that takes compatible input to this one, pairwise compose the state and outputs of each scan on a common input stream.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], and scan2.apply([a_1, ..., a_n] = [p_1, ..., p_n] then join will return a scan whose apply method returns [(o_1, p_1), ..., (o_2, p_2)]. In other words: scan.join(scan2)(foo) == scan(foo).zip(scan2(foo))

  17. def joinWithIndex: Aux[I, (State, Long), (O, Long)]

    Permalink

    For every foo, scan.joinWithIndex(foo) == scan(foo).zipWithIndex.

    For every foo, scan.joinWithIndex(foo) == scan(foo).zipWithIndex.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], return a scan that whose apply method, when given the same input, will return [(o_1, 1), ..., (o_n, n)].

  18. def joinWithInput[I1 <: I]: Aux[I1, State, (O, I1)]

    Permalink

    Return a scan that is semantically identical to this.join(Scan.identity[I1]), but where we don't pollute the State by pairing it redundantly with Unit.

    Return a scan that is semantically identical to this.join(Scan.identity[I1]), but where we don't pollute the State by pairing it redundantly with Unit.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n, then this results in a Scan whose apply method returns [(o_1, a_1), ..., (o_n, a_n)] when given the same input.

  19. def joinWithPosteriorState: Aux[I, State, (O, State)]

    Permalink

    Return a scan whose output is paired with the state of the scan after each input updates the state.

    Return a scan whose output is paired with the state of the scan after each input updates the state.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i) and state_0 = initialState, return a scan that whose apply method, when given inputs [a_1, ..., a_n] will return [(o_1, state_1), ..., (o_n, state_n].

  20. def joinWithPriorState: Aux[I, State, (State, O)]

    Permalink

    Return a scan whose output is paired with the state of the scan before each input updates the state.

    Return a scan whose output is paired with the state of the scan before each input updates the state.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i) and state_0 = initialState, return a scan that whose apply method, when given inputs [a_1, ..., a_n] will return [(o_1, state_0), ..., (o_n, state_(n-1))].

  21. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  24. def replaceState(newInitialState: ⇒ State): Aux[I, State, O]

    Permalink

    Return a new scan that is the same as this scan, but with a different initialState.

  25. def scanIterator(iter: Iterator[I]): Iterator[O]

    Permalink

    returns

    If iter = Iterator(a_1, ..., a_n), return: Iterator(o_1, ..., o_n) where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i) and state_0 = initialState

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

    Permalink
    Definition Classes
    AnyRef
  27. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  28. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. def zip[I2, O2](scan2: Scan[I2, O2]): Aux[(I, I2), (State, State), (O, O2)]

    Permalink

    Compose two scans pairwise such that, when given pairwise zipped inputs, the resulting scan will output pairwise zipped outputs.

    Compose two scans pairwise such that, when given pairwise zipped inputs, the resulting scan will output pairwise zipped outputs.

    returns

    If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of the form [o_1, ..., o_n], and scan2.apply([b_1, ..., b_n] = [p_1, ..., p_n] then zip will return a scan whose apply method, when given input [(a_1, b_1), ..., (a_n, b_n)] results in the output [(o_1, p_1), ..., (o_2, p_2)]. In other words: scan.zip(scan2)(foo.zip(bar)) == scan(foo).zip(scan2(bar))

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped