h8io.stages.std

package h8io.stages.std

Members list

Type members

Classlikes

object Coalesce extends Fn[Either[Any, Any], Any]

A stage that collapses an Either by returning whichever side contains the value.

A stage that collapses an Either by returning whichever side contains the value.

Coalesce takes an Either[T, T] and returns the contained value, regardless of whether it is Left or Right. It always succeeds (h8io.stages.Status.Success) and never changes state, because it is a h8io.stages.base.Fn.

Example:

val stage: Fn[Either[String, String], String] = Coalesce[String]

Attributes

Supertypes
trait Fn[Either[Any, Any], Any]
trait SAMStage[Either[Any, Any], Any, Nothing]
trait Stagnation[Either[Any, Any], Any, Nothing]
trait Evolution[Either[Any, Any], Any, Nothing]
trait Fruitful[Either[Any, Any], Any, Nothing]
trait Stage[Either[Any, Any], Any, Nothing]
trait Either[Any, Any] => Yield[Either[Any, Any], Any, Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Coalesce.type
object Complete extends Endo[Any, Nothing]

A stage that immediately signals pipeline completion without dropping the input value.

A stage that immediately signals pipeline completion without dropping the input value.

Complete always yields h8io.stages.Status.Complete while still passing the input through as the output. It is useful as the terminal element in a pipeline to stop further processing after a condition is met (see h8io.stages.operators.CompleteIfSome).

The singleton operates on Any and can be safely cast to any Fruitful.Endo[T] via apply[T].

Attributes

Supertypes
trait FruitfulStaticStage[Any, Any, Nothing]
trait Fruitful[Any, Any, Nothing]
trait SAMStage[Any, Any, Nothing]
trait Stagnation[Any, Any, Nothing]
trait Evolution[Any, Any, Nothing]
trait Stage[Any, Any, Nothing]
trait Any => Yield[Any, Any, Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Complete.type
final case class Const[+O](out: O) extends Fn[Any, O]

A stage that always produces the same constant output, ignoring its input.

A stage that always produces the same constant output, ignoring its input.

Const wraps a fixed value out and returns it on every invocation, always succeeding (h8io.stages.Status.Success). Because it is a h8io.stages.base.Fn, it is stateless and can be reused freely.

Example:

val always42: Stage[Any, Int, Nothing] = Const(42)

Type parameters

O

the output type (covariant)

Value parameters

out

the constant value to produce on every invocation

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Fn[Any, O]
trait SAMStage[Any, O, Nothing]
trait Stagnation[Any, O, Nothing]
trait Evolution[Any, O, Nothing]
trait Fruitful[Any, O, Nothing]
trait Stage[Any, O, Nothing]
trait Any => Yield[Any, O, Nothing]
class Object
trait Matchable
class Any
Show all
object Countdown

Factory for Countdown stages.

Factory for Countdown stages.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Countdown.type
final case class Countdown[T](i: Long, n: Long) extends Endo[T, Nothing], Endo[T, Nothing]

An endomorphic stage that passes its input through for exactly n invocations and then signals pipeline completion.

An endomorphic stage that passes its input through for exactly n invocations and then signals pipeline completion.

On each of the first n − 1 calls the stage yields h8io.stages.Status.Success and decrements its counter. On the n-th call it yields h8io.stages.Status.Complete and resets to n. After any h8io.stages.Status.Complete the stage also resets to n, ready for reuse.

Countdown is fully immutable: each state transition creates a new instance rather than mutating the current one.

Preconditions (checked at construction via assume):

  • n > 0
  • 1 ≤ i ≤ n

Type parameters

T

the value type passed through unchanged

Value parameters

i

the remaining number of successful yields before completion (1 ≤ i ≤ n)

n

the total period length (must be positive)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait SAMStage[T, T, Nothing]
trait Stagnation[T, T, Nothing]
trait Evolution[T, T, Nothing]
trait Fruitful[T, T, Nothing]
trait Stage[T, T, Nothing]
trait T => Yield[T, T, Nothing]
class Object
trait Matchable
class Any
Show all
sealed case class DeadEnd(_dispose: () => Unit) extends StaticStage[Any, Nothing, Nothing]

A terminal stage that never produces an output value.

A terminal stage that never produces an output value.

Every invocation of apply returns a h8io.stages.Yield.None with h8io.stages.Status.Complete, immediately signaling that the pipeline is finished.

DeadEnd is the natural "end-of-stream" marker and is also returned by Countdown.apply when n ≤ 0 and by h8io.stages.operators.LocalSoftDeadline when the duration is non-positive.

An optional _dispose hook can be supplied at construction to release resources when the stage is disposed; the companion object DeadEnd uses a no-op hook.

Value parameters

_dispose

a thunk invoked by h8io.stages.Evolution.dispose; defaults to a no-op in the companion object

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait StaticStage[Any, Nothing, Nothing]
trait SAMStage[Any, Nothing, Nothing]
trait Stagnation[Any, Nothing, Nothing]
trait Evolution[Any, Nothing, Nothing]
trait Stage[Any, Nothing, Nothing]
trait Any => Yield[Any, Nothing, Nothing]
class Object
trait Matchable
class Any
Show all
Known subtypes
object DeadEnd
object DeadEnd extends DeadEnd

Default no-op DeadEnd instance.

Default no-op DeadEnd instance.

Use DeadEnd directly as a stage or call DeadEnd(_dispose) to create a variant with a custom disposal hook.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class DeadEnd
trait Serializable
trait Product
trait Equals
trait StaticStage[Any, Nothing, Nothing]
trait SAMStage[Any, Nothing, Nothing]
trait Stagnation[Any, Nothing, Nothing]
trait Evolution[Any, Nothing, Nothing]
trait Stage[Any, Nothing, Nothing]
trait Any => Yield[Any, Nothing, Nothing]
class Object
trait Matchable
class Any
Show all
Self type
DeadEnd.type

Factory for GlobalSoftDeadline stages.

Factory for GlobalSoftDeadline stages.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
final class GlobalSoftDeadline[T] extends Endo[T, Nothing]

An endomorphic stage that passes values through as long as a wall-clock deadline has not elapsed.

An endomorphic stage that passes values through as long as a wall-clock deadline has not elapsed.

The deadline is measured from the moment this instance is created: the timestamp ts is captured once at construction using now(). On each invocation, if the elapsed time (now() - ts) is less than duration (in nanoseconds), the stage yields h8io.stages.Status.Success; otherwise it yields h8io.stages.Status.Complete.

The deadline is ''global'' in the sense that it is fixed at construction and never resets, unlike h8io.stages.operators.LocalSoftDeadline which restarts its window with each new unit of work.

Type parameters

T

the value type passed through unchanged

Value parameters

duration

the maximum allowed elapsed time in nanoseconds

now

a supplier of the current time in nanoseconds (typically System.nanoTime _)

Attributes

Companion
object
Supertypes
trait FruitfulStaticStage[T, T, Nothing]
trait Fruitful[T, T, Nothing]
trait SAMStage[T, T, Nothing]
trait Stagnation[T, T, Nothing]
trait Evolution[T, T, Nothing]
trait Stage[T, T, Nothing]
trait T => Yield[T, T, Nothing]
class Object
trait Matchable
class Any
Show all
object Identity extends Endo[Any]

A stage that passes its input through unchanged.

A stage that passes its input through unchanged.

Identity is a singleton h8io.stages.base.Fn that acts as the identity function: given any value, it returns the same value. It always succeeds (h8io.stages.Status.Success) and never changes state.

The singleton operates on Any and can be safely cast to any specific Fn.Endo[T] via the apply[T] method, avoiding allocation on every use.

Example:

val stage: Fn.Endo[String] = Identity[String]

Attributes

Supertypes
trait Fn[Any, Any]
trait SAMStage[Any, Any, Nothing]
trait Stagnation[Any, Any, Nothing]
trait Evolution[Any, Any, Nothing]
trait Fruitful[Any, Any, Nothing]
trait Stage[Any, Any, Nothing]
trait Any => Yield[Any, Any, Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Identity.type
object Scan

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Scan.type
final case class Scan[T, +E](op: Stage[(T, T), T, E]) extends Endo[T, E]

An endomorphic stage that folds its own inputs into a running accumulator across pipeline runs, via the binary operation stage op — the running-total counterpart of h8io.stages.cycles.Reduce and h8io.stages.cycles.Fold.

An endomorphic stage that folds its own inputs into a running accumulator across pipeline runs, via the binary operation stage op — the running-total counterpart of h8io.stages.cycles.Reduce and h8io.stages.cycles.Fold.

Unlike the h8io.stages.cycles family, Scan has no inner stage and no cycle: it consumes one external input per outer run and threads its own accumulator from one run to the next. The first input becomes the accumulator unchanged, without invoking op (the classic seedless reduce, seeded from the pipeline's own input stream instead of a single seed value); each subsequent input is folded via op((accumulator, input)) and the result — the new running total — is emitted immediately, ready for the next run.

When op is applied but itself yields no output — e.g. it filters some inputs out — the accumulator is left unchanged rather than discarded, exactly as in Reduce/Fold, and Scan itself yields nothing for that run.

Since Scan has no separate alterand, the status of a run is simply the status op produced (or Success, for the seeding run in which op is skipped) — there is nothing else to combine it with. Whenever that status is h8io.stages.Status.Complete, the next generation resets to a fresh, unseeded Scan instead of continuing to accumulate — mirroring how h8io.stages.std.Countdown resets on any non-Success status: Complete marks one logical unit of work as finished, and the next external input starts a new one, seeding from scratch.

Type parameters

E

the error type (covariant)

T

the accumulator and input type (invariant: threaded through as both input and output of op)

Value parameters

op

the binary operation stage folding the accumulator and a new input into the next accumulator

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait Stage[T, T, E]
trait T => Yield[T, T, E]
class Object
trait Matchable
class Any
Show all
object Swap extends Fn[(Any, Any), (Any, Any)]

A stage that swaps the two elements of a pair.

A stage that swaps the two elements of a pair.

Swap is a singleton h8io.stages.base.Fn: given (a, b), it returns (b, a). It always succeeds (h8io.stages.Status.Success) and never changes state.

The singleton operates on (Any, Any) and can be safely cast to any specific pair type via the apply[L, R] method, avoiding allocation on every use.

h8io.stages.cycles.Reduce and h8io.stages.cycles.Fold both call op in the "left" convention, op((accumulator, output)). Composing Swap[R, O] ~> op in front of an op written in the opposite convention — (output, accumulator) — adapts it to the shape Reduce/Fold expect, without needing a separate ReduceRight/FoldRight operator: for a non-commutative op, this changes which side each value ends up on.

Example:

val stage: Fn[(Int, String), (String, Int)] = Swap[Int, String]

Attributes

Supertypes
trait Fn[(Any, Any), (Any, Any)]
trait SAMStage[(Any, Any), (Any, Any), Nothing]
trait Stagnation[(Any, Any), (Any, Any), Nothing]
trait Evolution[(Any, Any), (Any, Any), Nothing]
trait Fruitful[(Any, Any), (Any, Any), Nothing]
trait Stage[(Any, Any), (Any, Any), Nothing]
trait ((Any, Any)) => Yield[(Any, Any), (Any, Any), Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Swap.type