PIso

public class PIso<S, T, A, B>

An Iso is a loss less invertible optic that defines an isomorphism between a type S and A.

A polimorphic PIso is useful when setting or modifying a value for a constructed type; e.g. PIso<<Option<Int>, Option<String>, Int?, String?>.

  • S: Source of a PIso.
  • T: Modified source of a PIso.
  • A: Focus of a PIso.
  • B: Modified target of a PIso.
  • Composes two PIsos.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PIso<A, B, C, D>) -> PIso<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PIso resulting from the sequential application of the two provided optics.

  • Composes a PIso with a Getter.

    Declaration

    Swift

    public static func + <C>(lhs: PIso<S, T, A, B>, rhs: Getter<A, C>) -> Getter<S, C>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A Getter resulting from the sequential application of the two provided optics.

  • Composes a PIso with a PLens.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PLens<A, B, C, D>) -> PLens<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PLens resulting from the sequential application of the two provided optics.

  • Composes a PIso with a PPrism.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PPrism<A, B, C, D>) -> PPrism<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PPrism resulting from the sequential application of the two provided optics.

  • Composes a PIso with a PAffineTraversal.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PAffineTraversal<A, B, C, D>) -> PAffineTraversal<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PAffineTraversal resulting from the sequential application of the two provided optics.

  • Composes a PIso with a PSetter.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PSetter<A, B, C, D>) -> PSetter<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PSetter resulting from the sequential application of the two provided optics.

  • Composes a PIso with a Fold.

    Declaration

    Swift

    public static func + <C>(lhs: PIso<S, T, A, B>, rhs: Fold<A, C>) -> Fold<S, C>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A Fold resulting from the sequential application of the two provided optics.

  • Composes a PIso with a PTraversal.

    Declaration

    Swift

    public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PTraversal<A, B, C, D>) -> PTraversal<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PTraversal resulting from the sequential application of the two provided optics.

  • Creates a PIso with two functions that form an isomorphism.

    Declaration

    Swift

    public init(get: @escaping (S) -> A, reverseGet: @escaping (B) -> T)

    Parameters

    get

    A function from the source to the focus.

    reverseGet

    A function from the modified target to the modified focus.

  • Gets the focus of an Iso.

    Declaration

    Swift

    public func get(_ s: S) -> A

    Parameters

    s

    Source.

    Return Value

    Focus of the provided source.

  • Gets the modified source of an Iso.

    Declaration

    Swift

    public func reverseGet(_ b: B) -> T

    Parameters

    b

    Modified target.

    Return Value

    Modified source of the provided modified target.

  • Lifts this PIso to a Functor level.

    Declaration

    Swift

    public func mapping<F>() -> PIso<Kind<F, S>, Kind<F, T>, Kind<F, A>, Kind<F, B>> where F : Functor

    Return Value

    A PIso that operates on the same type arguments but lifted to a Functor.

  • Modify the target of a PIso with a Functor function.

    Declaration

    Swift

    public func modifyF<F: Functor>(_ s: S, _ f: @escaping (A) -> Kind<F, B>) -> Kind<F, T>

    Parameters

    s

    Source.

    f

    Function providing a modified target at the Functor level.

    Return Value

    Modified source at the Functor level.

  • Lifts a function with a Functor.

    Declaration

    Swift

    public func liftF<F: Functor>(_ f: @escaping (A) -> Kind<F, B>) -> (S) -> Kind<F, T>

    Parameters

    f

    Function with a Functor from focus to modified target.

    Return Value

    Function with a Functor from source to modified source.

  • Reverses the source and focus of this PIso.

    Declaration

    Swift

    public func reverse() -> PIso<B, A, T, S>

    Return Value

    A PIso with reversed source and focus.

  • Checks if the focus statisfies a predicate.

    Declaration

    Swift

    public func find(_ s: S, _ predicate: (A) -> Bool) -> Option<A>

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    A present option with the focus, if it satisfies the predicate; or none, otherwise.

  • Sets the focus of a PIso.

    Declaration

    Swift

    public func set(_ b: B) -> T

    Parameters

    b

    Focus.

    Return Value

    Source for the provided focus.

  • Pairs two disjoint PIso.

    Declaration

    Swift

    public func split<S1, T1, A1, B1>(_ other: PIso<S1, T1, A1, B1>) -> PIso<(S, S1), (T, T1), (A, A1), (B, B1)>

    Parameters

    other

    A disjoint PIso to pair with this one.

    Return Value

    A PIso that operates on tuples corresponding to the two joined PIso.

  • Pairs this PIso with another type, placing this as the first element.

    Declaration

    Swift

    public func first<C>() -> PIso<(S, C), (T, C), (A, C), (B, C)>

    Return Value

    A PIso that operates on tuples where the second argument remains unchanged.

  • Pairs this PIso with another type, placing this as the second element.

    Declaration

    Swift

    public func second<C>() -> PIso<(C, S), (C, T), (C, A), (C, B)>

    Return Value

    A PIso that operates on tuples where the first argument remains unchaged.

  • Creates the sum of this PIso with another type, placing this as the left side.

    Declaration

    Swift

    public func left<C>() -> PIso<Either<S, C>, Either<T, C>, Either<A, C>, Either<B, C>>

    Return Value

    A PIso that operates on Eithers where the right side remains unchanged.

  • Creates the sum of this PIso with another type, placing this as the right side.

    Declaration

    Swift

    public func right<C>() -> PIso<Either<C, S>, Either<C, T>, Either<C, A>, Either<C, B>>

    Return Value

    A PIso that operates on Eithers where the left side remains unchaged.

  • Composes this with a PIso.

    Declaration

    Swift

    public func compose<C, D>(_ other: PIso<A, B, C, D>) -> PIso<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PIso resulting from applying the two optics sequentially.

  • Composes this with a Getter.

    Declaration

    Swift

    public func compose<C>(_ other: Getter<A, C>) -> Getter<S, C>

    Parameters

    other

    Value to compose with.

    Return Value

    A Getter resulting from applying the two optics sequentially.

  • Composes this with a PLens.

    Declaration

    Swift

    public func compose<C, D>(_ other: PLens<A, B, C, D>) -> PLens<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PLens resulting from applying the two optics sequentially.

  • Composes this with a PPrism.

    Declaration

    Swift

    public func compose<C, D>(_ other: PPrism<A, B, C, D>) -> PPrism<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PPrism resulting from applying the two optics sequentially.

  • Composes this with a PAffineTraversal.

    Declaration

    Swift

    public func compose<C, D>(_ other: PAffineTraversal<A, B, C, D>) -> PAffineTraversal<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting from applying the two optics sequentially.

  • Composes this with a PSetter.

    Declaration

    Swift

    public func compose<C, D>(_ other: PSetter<A, B, C, D>) -> PSetter<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PSetter resulting from applying the two optics sequentially.

  • Composes this with a Fold.

    Declaration

    Swift

    public func compose<C>(_ other: Fold<A, C>) -> Fold<S, C>

    Parameters

    other

    Value to compose with.

    Return Value

    A Fold resulting from applying the two optics sequentially.

  • Composes this with a PTraversal.

    Declaration

    Swift

    public func compose<C, D>(_ other: PTraversal<A, B, C, D>) -> PTraversal<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PTraversal resulting from applying the two optics sequentially.

  • Converts this into a Getter.

    Declaration

    Swift

    public var asGetter: Getter<S, A> { get }
  • Converts this into a PLens.

    Declaration

    Swift

    public var asLens: PLens<S, T, A, B> { get }
  • Converts this into a PPrism.

    Declaration

    Swift

    public var asPrism: PPrism<S, T, A, B> { get }
  • Converts this into a PAffineTraversal.

    Declaration

    Swift

    public var asAffineTraversal: PAffineTraversal<S, T, A, B> { get }
  • Converts this into a PSetter.

    Declaration

    Swift

    public var asSetter: PSetter<S, T, A, B> { get }
  • Converts this into a Fold.

    Declaration

    Swift

    public var asFold: Fold<S, A> { get }
  • Converts this into a PTraversal.

    Declaration

    Swift

    public var asTraversal: PTraversal<S, T, A, B> { get }
  • Checks if the target fulfils a predicate.

    Declaration

    Swift

    public func exists(_ s: S, _ predicate: (A) -> Bool) -> Bool

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    A boolean value indicating if the target matches the provided predicate.

  • Modifies the focus with a function.

    Declaration

    Swift

    public func modify(_ s: S, _ f: @escaping (A) -> B) -> T

    Parameters

    s

    Source.

    f

    Function modifying the focus.

    Return Value

    Modified target.

  • Lifts a function to modify the focus.

    Declaration

    Swift

    public func lift(_ f: @escaping (A) -> B) -> (S) -> T

    Parameters

    f

    Function modifying the focus.

    Return Value

    Function from source to modified source.