# PIso

``public class PIso<S, T, A, B> : PIsoOf<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 `PIso`s.

#### 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 `POptional`.

#### Declaration

Swift

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

#### Parameters

 ``` lhs ``` Left side of the composition. ``` rhs ``` Right side of the composition.

#### Return Value

A `POptional` 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.

• ``` init(get:reverseGet:) ```

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.
• ``` get(_:) ```

Gets the focus of an Iso.

#### Declaration

Swift

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

#### Parameters

 ``` s ``` Source.

#### Return Value

Focus of the provided source.

• ``` reverseGet(_:) ```

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.

• ``` mapping() ```

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`.

• ``` modifyF(_:_:) ```

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.

• ``` liftF(_:) ```

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.

• ``` reverse() ```

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.

• ``` find(_:_:) ```

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.

• ``` set(_:) ```

Sets the focus of a `PIso`.

#### Declaration

Swift

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

#### Parameters

 ``` b ``` Focus.

#### Return Value

Source for the provided focus.

• ``` split(_:) ```

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`.

• ``` first() ```

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.

• ``` second() ```

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.

• ``` left() ```

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 `Either`s where the right side remains unchanged.

• ``` right() ```

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 `Either`s where the left side remains unchaged.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

Composes this with a `POptional`.

#### Declaration

Swift

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

#### Parameters

 ``` other ``` Value to compose with.

#### Return Value

A `POptional` resulting from applying the two optics sequentially.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

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.

• ``` compose(_:) ```

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.

• ``` asGetter ```

Converts this into a `Getter`.

#### Declaration

Swift

``public var asGetter: Getter<S, A> { get }``
• ``` asLens ```

Converts this into a `PLens`.

#### Declaration

Swift

``public var asLens: PLens<S, T, A, B> { get }``
• ``` asPrism ```

Converts this into a `PPrism`.

#### Declaration

Swift

``public var asPrism: PPrism<S, T, A, B> { get }``
• ``` asOptional ```

Converts this into a `POptional`.

#### Declaration

Swift

``public var asOptional: POptional<S, T, A, B> { get }``
• ``` asSetter ```

Converts this into a `PSetter`.

#### Declaration

Swift

``public var asSetter: PSetter<S, T, A, B> { get }``
• ``` asFold ```

Converts this into a `Fold`.

#### Declaration

Swift

``public var asFold: Fold<S, A> { get }``
• ``` asTraversal ```

Converts this into a `PTraversal`.

#### Declaration

Swift

``public var asTraversal: PTraversal<S, T, A, B> { get }``
• ``` exists(_:_:) ```

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.

• ``` modify(_:_:) ```

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.

• ``` lift(_:) ```

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.