Moore

public final class Moore<E, V> : MooreOf<E, V>

Moore represents Moore machines that hold values of type V and handle inputs of type E.

  • Value hold in this Moore machine.

    Declaration

    Swift

    public let view: V
  • Function to handle inputs to the Moore machine.

    Declaration

    Swift

    public let handle: (E) -> Moore<E, V>
  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ value: MooreOf<E, V>) -> Moore<E, V>

    Parameters

    value

    Value in the higher-kind form.

    Return Value

    Value cast to Moore.

  • Creates a Moore machine from a hidden initial state and a function that provides the next value and handling function.

    Declaration

    Swift

    public static func unfold<S>(
        _ state: S,
        _ next: @escaping (S) -> (V, (E) -> S)) -> Moore<E, V>

    Parameters

    state

    Initial state.

    next

    Function to determine the next value and handling function.

    Return Value

    A Moore machine described from the input values.

  • Creates a Moore machine from an initial state, a rendering function and an update function.

    Declaration

    Swift

    public static func from<S>(
        initialState: S,
        render: @escaping (S) -> V,
        update: @escaping (S, E) -> S) -> Moore<E, V>

    Parameters

    initialState

    Initial state.

    render

    Rendering function.

    update

    Update function.

    Return Value

    A Moore machine described from the input functions.

  • Creates a Moore machine from an initial state, a rendering function and an update function.

    Declaration

    Swift

    public static func from<S>(
        initialState: S,
        render: @escaping (S) -> V,
        update: @escaping (E) -> State<S, S>) -> Moore<E, V>

    Parameters

    initialState

    Initial state.

    render

    Rendering function.

    update

    Update function.

    Return Value

    A Moore machine described from the input functions.

  • Initializes a Moore machine.

    Declaration

    Swift

    public init(view: V, handle: @escaping (E) -> Moore<E, V>)

    Parameters

    view

    Value wrapped in the machine.

    handle

    Function to handle inputs to the machine.

  • Transforms the inputs this machine is able to handle.

    Declaration

    Swift

    public func contramapInput<EE>(_ f: @escaping (EE) -> E) -> Moore<EE, V>

    Parameters

    f

    Transforming funtion.

    Return Value

    A Moore machine that works on the new type of inputs.

  • Creates a Moore machine that logs the inputs it receives.

    Declaration

    Swift

    static var log: Moore<E, E> { get }