Lens
public struct Lens<A, B>
Enables read and copy-on-write access for an entity’s property in a datastructure.
Some examples can be found in this blog post.
-
Serves as getter.
Declaration
Swift
public let from: (A) -> B
-
Serves as setter.
Declaration
Swift
public let to: (B, A) -> A
-
Creates a lens.
Parameter
Parameter from: Returns a property from a given value.Parameter
Parameter of: Sets a property to a given value.Declaration
Swift
public init(from: @escaping (A) -> B, to: @escaping (B, A) -> A)
Parameters
from
Returns a property from a given value.
of
Sets a property to a given value.
-
Creates a new lens by using a child lens.
Parameter
Parameter lens: The lens to be used as child ofself
.Returns
A new lens from the current type to the given.Declaration
Swift
public func child<C>(with lens: Lens<B, C>) -> Lens<A, C>
Parameters
lens
The lens to be used as child of
self
.Return Value
A new lens from the current type to the given.
-
Creates a new lens by using a child lens. Convenience method for
Lens.child(lens:)
.Parameter
Parameter from:Lens.from
to be used as a child-Parameter
Parameter to:Lens.to
to be used as a child-Returns
A new lens from the current type to the given.Declaration
Swift
public func child<C>(from: @escaping (B) -> C, to: @escaping (C, B) -> B) -> Lens<A, C>
Parameters
from
Lens.from
to be used as a child-to
Lens.to
to be used as a child-Return Value
A new lens from the current type to the given.
-
Creates a new lens by using a child lens. Reversed convenience method for
Lens.child(lens:)
.Parameter
Parameter lens: The lens to be used as parent ofself
.Returns
A new, combined lens.Declaration
Swift
public func asChild<S>(of parent: Lens<S, A>) -> Lens<S, B>
Parameters
lens
The lens to be used as parent of
self
.Return Value
A new, combined lens.
-
Creates a new lens by using a child lens. Reversed convenience method for
Lens.child(lens:)
.Parameter
Parameter lens: The lens to be used as parent ofself
.Returns
A new, combined lens.Declaration
Swift
public func asChild<S>(from: @escaping (S) -> A, to: @escaping (A, S) -> S) -> Lens<S, B>
Parameters
lens
The lens to be used as parent of
self
.Return Value
A new, combined lens.