Schedule

public class Schedule<R, A, State, B>

A stateful, effectful and recurring schedule of actions.

A schedule consumes values of type A and based on its internal state of type State, decides to continue or stop. Every decision has a delay and an output of type B.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules.

    Declaration

    Swift

    public func and<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), (B, C)>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes this schedule with another one, providing a new schedule that needs the input of both schedules and provides the output of both. It continues as long as both continue, using the maximum delay of the two schedules.

    Declaration

    Swift

    public func split<State2, C, D>(_ that: Schedule<R, C, State2, D>) -> Schedule<R, (A, C), (State, State2), (B, D)>

    Parameters

    that

    Schedule to be composed with this one.

  • Chooses between two schedules with different inputs and outputs.

    Declaration

    Swift

    public func choose<State2, C, D>(_ that: Schedule<R, C, State2, D>) -> Schedule<R, Either<A, C>, (State, State2), Either<B, D>>

    Parameters

    that

    Schedule to be composed with this one.

  • Chooses between two schedules with different inputs and the same output.

    Declaration

    Swift

    public func choose<State2, C>(_ that: Schedule<R, C, State2, B>) -> Schedule<R, Either<A, C>, (State, State2), B>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules.

    Declaration

    Swift

    public func zip<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), (B, C)>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules, and ignoring the output of this schedule.

    Declaration

    Swift

    public func zipRight<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), C>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules, and ignoring the output of the provided schedule.

    Declaration

    Swift

    public func zipLeft<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), B>

    Parameters

    that

    Schedule to be composed with this one.

  • Pipes the output of this schedule as the input of the provided one. Effects described by this schedule will always be performed before the effects described by the second schedule.

    Declaration

    Swift

    public func pipe<State2, C>(_ that: Schedule<R, B, State2, C>) -> Schedule<R, A, (State, State2), C>

    Parameters

    that

    Schedule to be piped after this one.

  • Pipes the output of the provided schedule as the input of this schedule. Effects described by the provided schedule will always be performed before the effects described by this schedule.

    Declaration

    Swift

    public func reversePipe<State2, C>(_ that: Schedule<R, C, State2, A>) -> Schedule<R, C, (State2, State), B>

    Parameters

    that

    Schedule to be piped before this one.

  • Composes with a schedule resulting in another one that continues as long as either schedule continues, using the minimum of the delays of the two schedules.

    Declaration

    Swift

    public func or<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), (B, C)>

    Parameters

    that

    Schedule to be composed with this one.

  • Adds a delay of the specified duration based on the output of this schedule.

    Declaration

    Swift

    public func addDelay(_ f: @escaping (B) -> DispatchTimeInterval) -> Schedule<R, A, State, B>

    Parameters

    f

    Function computing the delay time based on the output of the schedule.

  • Adds a delay of the specified duration based on the output of this schedule.

    Declaration

    Swift

    public func addDelayM(_ f: @escaping (B) -> EnvIO<R, Never, DispatchTimeInterval>) -> Schedule<R, A, State, B>

    Parameters

    f

    An effectful function that provides the delay time based on the output of the schedule.

  • Adds a delay of the specified duration based on the output of this schedule.

    Declaration

    Swift

    public func addDelay(_ f: @escaping (B) -> TimeInterval) -> Schedule<R, A, State, B>

    Parameters

    f

    Function computing the delay time based on the output of the schedule.

  • Adds a delay of the specified duration based on the output of this schedule.

    Declaration

    Swift

    public func addDelayM(_ f: @escaping (B) -> EnvIO<R, Never, TimeInterval>) -> Schedule<R, A, State, B>

    Parameters

    f

    An effectful function that provides the delay time based on the output of the schedule.

  • Composes two schedules with the same input and output by applying them sequentially. It executes the first to completion, and then executes the second.

    Declaration

    Swift

    public func andThen<State2>(_ that: Schedule<R, A, State2, B>) -> Schedule<R, A, Either<State, State2>, B>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes two schedules with the same input but different outputs by applying them sequentially. It executes the first to completion, and then executes the second.

    Declaration

    Swift

    public func andThenEither<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, Either<State, State2>, Either<B, C>>

    Parameters

    that

    Schedule to be composed with this one.

  • Transforms the output of this schedule to a fixed value.

    Declaration

    Swift

    public func `as`<C>(_ c: C) -> Schedule<R, A, State, C>

    Parameters

    c

    Fixed value to return as output of this schedule.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules.

    Declaration

    Swift

    public func both<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), (B, C)>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes this schedule with another one, providing a new schedule that continues as long as both continue, using the maximum delay of the two schedules, and combining the outputs of both using the provided function.

    Declaration

    Swift

    public func bothWith<State2, C, D>(_ that: Schedule<R, A, State2, C>, _ f: @escaping (B, C) -> D) -> Schedule<R, A, (State, State2), D>

    Parameters

    that

    Schedule to be composed with this one.

    f

    Transforming function.

  • Peeks at the output produced by this schedule and executes a test to determine if the schedule should continue or not.

    Declaration

    Swift

    public func check(_ test: @escaping (A, B) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, B>

    Parameters

    test

    Effectful predicate to determine if the schedule should continue or not based on the current input and output.

  • Collects all the output of this schedule in an array.

    Declaration

    Swift

    public func collectAll() -> Schedule<R, A, (State, [B]), [B]>
  • Pipes the output of the provided schedule as the input of this schedule. Effects described by the provided schedule will always be performed before the effects described by this schedule.

    Declaration

    Swift

    public func compose<State2, C>(_ that: Schedule<R, C, State2, A>) -> Schedule<R, C, (State2, State), B>

    Parameters

    that

    Schedule to be piped before this one.

  • Provides an schedule that deals with a narrower class of inputs than this schedule.

    Declaration

    Swift

    public func contramap<AA>(_ f: @escaping (AA) -> A) -> Schedule<R, AA, State, B>

    Parameters

    f

    Function transforming the input of this schedule.

  • Provides an schedule that contramaps the input and maps the output with the provided functions.

    Declaration

    Swift

    public func dimap<AA, C>(_ f: @escaping (AA) -> A, _ g: @escaping (B) -> C) -> Schedule<R, AA, State, C>

    Parameters

    f

    Function to contramap.

    g

    Function to map.

  • Composes with a schedule resulting in another one that continues as long as either schedule continues, using the minimum of the delays of the two schedules.

    Declaration

    Swift

    public func either<State2, C>(_ that: Schedule<R, A, State2, C>) -> Schedule<R, A, (State, State2), (B, C)>

    Parameters

    that

    Schedule to be composed with this one.

  • Composes with a schedule resulting in another one that continues as long as either schedule continues, using the minimum of the delays of the two schedules, and transforming the outputs with the provided function.

    Declaration

    Swift

    public func eitherWith<State2, C, D>(_ that: Schedule<R, A, State2, C>, _ f: @escaping (B, C) -> D) -> Schedule<R, A, (State, State2), D>

    Parameters

    that

    Schedule to be composed with this one.

    f

    Transforming function.

  • Puts this schedule into the first element of a tuple and passes an unmodified element as the second element of the tuple.

    Declaration

    Swift

    public func first<C>() -> Schedule<R, (A, C), (State, Unit), (B, C)>
  • Provides a schedule that folds the outputs of this one.

    Declaration

    Swift

    public func fold<Z>(_ z: Z, _ f: @escaping (Z, B) -> Z) -> Schedule<R, A, (State, Z), Z>

    Parameters

    z

    Initial value for the folding process.

    f

    Folding function.

  • Returns a new schedule that loops this one forever, resetting the state when this schedule is completed.

    Declaration

    Swift

    public func forever() -> Schedule<R, A, State, B>
  • Returns a new schedule with the specified initial state transformed by a function.

    Declaration

    Swift

    public func initialized(_ f: @escaping (EnvIO<R, Never, State>) -> EnvIO<R, Never, State>) -> Schedule<R, A, State, B>

    Parameters

    f

    Function transforming the initial state.

  • Puts the schedule into the left side of an Either and passes an unmodified value as the right side of the Either.

    Declaration

    Swift

    public func left<C>() -> Schedule<R, Either<A, C>, (State, Unit), Either<B, C>>
  • Transforms the output of this schedule with the provided function.

    Declaration

    Swift

    public func map<C>(_ f: @escaping (B) -> C) -> Schedule<R, A, State, C>

    Parameters

    f

    Transforming function.

  • Provides a new schedule that emits the number of repetitions of this schedule.

    Declaration

    Swift

    public func repetitions() -> Schedule<R, A, (State, Int), Int>
  • Puts the schedule into the right side of an Either and passes an unmodified value as the left side of the Either.

    Declaration

    Swift

    public func right<C>() -> Schedule<R, Either<C, A>, (Unit, State), Either<C, B>>
  • Puts this schedule into the second element of a tuple and passes an unmodified element as the first element of the tuple.

    Declaration

    Swift

    public func second<C>() -> Schedule<R, (C, A), (Unit, State), (C, B)>
  • Performs an additional effect for every input.

    Declaration

    Swift

    public func tapInput(_ f: @escaping (A) -> EnvIO<R, Never, Void>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful function to run after every input.

  • Performs an additional effect for every output.

    Declaration

    Swift

    public func tapOutput(_ f: @escaping (B) -> EnvIO<R, Never, Void>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful function to run after every output.

  • Wipes out the output produced by this schedule.

    Declaration

    Swift

    public func void() -> Schedule<R, A, State, Void>
  • Provides a schedule that iterates this schedule until the input matches a given predicate.

    Declaration

    Swift

    public func untilInput(_ f: @escaping (A) -> Bool) -> Schedule<R, A, State, B>

    Parameters

    f

    Predicate to test the input of this schedule.

  • Provides a schedule that iterates this schedule until the input matches a given effectful predicate.

    Declaration

    Swift

    public func untilInputM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful predicate to test the input of this schedule.

  • Provides a schedule that iterates this schedule until the output matches a given predicate.

    Declaration

    Swift

    public func untilOutput(_ f: @escaping (B) -> Bool) -> Schedule<R, A, State, B>

    Parameters

    f

    Predicate to test the output of this schedule.

  • Provides a schedule that iterates this schedule until the output matches a given effectful predicate.

    Declaration

    Swift

    public func untilOutputM(_ f: @escaping (B) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful predicate to test the output of this schedule.

  • Provides a schedule that iterates this schedule while the input matches a given predicate.

    Declaration

    Swift

    public func whileInput(_ f: @escaping (A) -> Bool) -> Schedule<R, A, State, B>

    Parameters

    f

    Predicate to test the input of this schedule.

  • Provides a schedule that iterates this schedule while the input matches a given effectful predicate.

    Declaration

    Swift

    public func whileInputM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful predicate to test the input of this schedule.

  • Provides a schedule that iterates this schedule while the output matches a given predicate.

    Declaration

    Swift

    public func whileOutput(_ f: @escaping (B) -> Bool) -> Schedule<R, A, State, B>

    Parameters

    f

    Predicate to test the output of this schedule.

  • Provides a schedule that iterates this schedule while the output matches a given effectful predicate.

    Declaration

    Swift

    public func whileOutputM(_ f: @escaping (B) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, B>

    Parameters

    f

    Effectful predicate to test the output of this schedule.

  • Provides a schedule that always recurs without delay and computes the output through subsequent applications of a function to an initial value.

    Declaration

    Swift

    public static func unfold(_ a: B, _ f: @escaping (B) -> B) -> Schedule<R, A, B, B>

    Parameters

    a

    Initial value.

    f

    Unfolding function.

  • Provides a schedule that always recurs without delay and computes the output through subsequent applications of an effectful function to an initial value.

    Declaration

    Swift

    public static func unfoldM(_ a: EnvIO<R, Never, B>, _ f: @escaping (B) -> EnvIO<R, Never, B>) -> Schedule<R, A, B, B>

    Parameters

    a

    Initial effect.

    f

    Unfolding effectful function.

  • Provides a schedule from the given schedule which transforms the delays into effectufl sleeps.

    Declaration

    Swift

    public static func delayed(_ s: Schedule<R, A, State, DispatchTimeInterval>) -> Schedule<R, A, State, DispatchTimeInterval>

    Parameters

    s

    A schedule producing time intervals.

  • Provides a schedule from the given schedule which transforms the delays into effectufl sleeps.

    Declaration

    Swift

    public static func delayed(_ s: Schedule<R, A, State, TimeInterval>) -> Schedule<R, A, State, TimeInterval>

    Parameters

    s

    A schedule producing time intervals.

  • Provides a schedule that recurs forever without a delay, returning the elapsed time since it began.

    Declaration

    Swift

    public static func elapsed() -> Schedule<R, A, (DispatchTime, DispatchTimeInterval), DispatchTimeInterval>
  • Provides a schedule that recurs until the specified duration elapsed, returning the total elapsed time.

    Declaration

    Swift

    public static func duration(_ interval: DispatchTimeInterval) -> Schedule<R, A, (DispatchTime, DispatchTimeInterval), DispatchTimeInterval>

    Parameters

    interval

    Time interval for this schedule to recur.

  • Provides a schedule that waits for the specified amount of time between each input. Returns the number of received inputs.

    Declaration

    Swift

    public static func spaced(_ interval: DispatchTimeInterval) -> Schedule<R, A, State, Int>

    Parameters

    interval

    Time interval to wait between each action.

  • Provides a schedule that waits for the specified amount of time between each input. Returns the number of received inputs.

    Declaration

    Swift

    public static func spaced(_ interval: TimeInterval) -> Schedule<R, A, State, Int>

    Parameters

    interval

    Time interval to wait between each action.

  • Provides a schedule that always recurs, waiting an amount of time between repetitions, given by an exponential backoff algorithm, and returning the current duration between recurrences.

    The time to wait is given by the formula base * pow(n + 1), where n is the number of repetitions so far.

    Declaration

    Swift

    public static func exponential(_ base: DispatchTimeInterval, factor: Double = 2.0) -> Schedule<R, A, Int, TimeInterval>

    Parameters

    base

    Base time interval to wait between repetitions.

    factor

    Factor for the exponential backoff. Defaults to 2.0.

  • Provides a schedule that always recurs, waiting an amount of time between repetitions, given by an exponential backoff algorithm, and returning the current duration between recurrences.

    The time to wait is given by the formula base * pow(n + 1), where n is the number of repetitions so far.

    Declaration

    Swift

    public static func exponential(_ base: TimeInterval, factor: Double = 2.0) -> Schedule<R, A, Int, TimeInterval>

    Parameters

    base

    Base time interval to wait between repetitions.

    factor

    Factor for the exponential backoff. Defaults to 2.0.

  • Provides a schedule that always recurs, waiting an amount of time between repetitions, given by a linear backoff algorithm, and returning the current duration between recurrences.

    The time to wait is given by the formula base * (n + 1), where n is the number of repetitions so far.

    Declaration

    Swift

    public static func linear(_ base: DispatchTimeInterval) -> Schedule<R, A, Int, TimeInterval>

    Parameters

    base

    Base time interval to wait between repetitions.

  • Provides a schedule that always recurs, waiting an amount of time between repetitions, given by a linear backoff algorithm, and returning the current duration between recurrences.

    The time to wait is given by the formula base * (n + 1), where n is the number of repetitions so far.

    Declaration

    Swift

    public static func linear(_ base: TimeInterval) -> Schedule<R, A, Int, TimeInterval>

    Parameters

    base

    Base time interval to wait between repetitions.

  • Provides a schedule that always recurs, increasing delays by summing the preceding two delays, as in the Fibonacci sequence. Returns the current duration between recurrences.

    Declaration

    Swift

    public static func fibonacci(_ one: DispatchTimeInterval) -> Schedule<R, A, (TimeInterval, TimeInterval), TimeInterval>

    Parameters

    one

    Time interval for the initial delay.

  • Provides a schedule that always recurs, increasing delays by summing the preceding two delays, as in the Fibonacci sequence. Returns the current duration between recurrences.

    Declaration

    Swift

    public static func fibonacci(_ one: TimeInterval) -> Schedule<R, A, (TimeInterval, TimeInterval), TimeInterval>

    Parameters

    one

    Time interval for the initial delay.

  • Provides a schedule that wipes out the output.

    Declaration

    Swift

    public static func void() -> Schedule<R, A, Unit, Void>
  • Provides a schedule that returns the input, unmodified.

    Declaration

    Swift

    public static func identity() -> Schedule<R, A, Unit, A>
  • Provides a schedule that recurs as long as the predicate evaluates to true.

    Declaration

    Swift

    public static func doWhile(_ f: @escaping (A) -> Bool) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Predicate to test the input.

  • Provides a schedule that recurs as long as the effectful predicate evaluates to true.

    Declaration

    Swift

    public static func doWhileM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Effectful predicate to test the input.

  • Provides a schedule that recurs until the predicate evaluates to true.

    Declaration

    Swift

    public static func doUntil(_ f: @escaping (A) -> Bool) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Predicate to test the input.

  • Provides a schedule that recurs until the effectful predicate evaluates to true.

    Declaration

    Swift

    public static func doUntilM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Effectful predicate to test the input.

  • Provides a schedule that executes an effect for every consumed input.

    Declaration

    Swift

    public static func tapInput(_ f: @escaping (A) -> EnvIO<R, Never, Void>) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Effectful function to run after every input.

  • Provides a schedule that executes an effect for every produced output.

    Declaration

    Swift

    public static func tapOutput(_ f: @escaping (A) -> EnvIO<R, Never, Void>) -> Schedule<R, A, Unit, A>

    Parameters

    f

    Effectful function to run after every output.

  • Provides a schedule that recurs forever, mapping input values through the provided function.

    Declaration

    Swift

    public static func from(function: @escaping (A) -> B) -> Schedule<R, A, State, B>

    Parameters

    function

    Transforming function.

  • Provides a schedule that recurs as long as the input is equal to a specific value.

    Declaration

    Swift

    public static func doWhileEquals(_ a: A) -> Schedule<R, A, Unit, A>

    Parameters

    a

    Value to compare the input of the schedule.

  • Provides a schedule that recurs as long as the input is not equal to a specific value.

    Declaration

    Swift

    public static func doUntilEquals(_ a: A) -> Schedule<R, A, Unit, A>

    Parameters

    a

    Value to compare the input of the schedule.

  • Provides a schedule that runs forever and emits the number of iterations it has performed.

    Declaration

    Swift

    public static func forever() -> Schedule<R, A, Int, Int>
  • Provides a schedule that recurs a specific number of times, emitting the current iteration it is in.

    Declaration

    Swift

    public static func recurs(_ n: Int) -> Schedule<R, A, Int, Int>

    Parameters

    n

    Number of iterations to perform.

  • Provides a schedule that recurs only once.

    Declaration

    Swift

    public static func once() -> Schedule<R, A, Int, Void>
  • Provides a schedule that recurs zero times.

    Declaration

    Swift

    public static func stop() -> Schedule<R, A, Int, Void>
  • Provides a schedule that never recurs.

    Declaration

    Swift

    public static func never() -> Schedule<R, Any, Never, Never>
  • Provides a schedule that recurs forever and collects all its outputs in an array.

    Declaration

    Swift

    public static func collectAll() -> Schedule<R, A, State, [A]>
  • Provides a schedule that collects its outputs in an array as long as the outputs match a given predicate.

    Declaration

    Swift

    public static func collectWhile(_ f: @escaping (A) -> Bool) -> Schedule<R, A, State, [A]>

    Parameters

    f

    Predicate to test the outputs.

  • Provides a schedule that collects its outputs in an array as long as the outputs match a given effectful predicate.

    Declaration

    Swift

    public static func collectWhileM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, [A]>

    Parameters

    f

    Effectful predicate to test the outputs.

  • Provides a schedule that collects its outputs in an array until an output matches a given predicate.

    Declaration

    Swift

    public static func collectUntil(_ f: @escaping (A) -> Bool) -> Schedule<R, A, State, [A]>

    Parameters

    f

    Predicate to test the outputs.

  • Provides a schedule that collects its outputs in an array until an output matches a given effectful predicate.

    Declaration

    Swift

    public static func collectUntilM(_ f: @escaping (A) -> EnvIO<R, Never, Bool>) -> Schedule<R, A, State, [A]>

    Parameters

    f

    Effectful predicate to test the outputs.