bow-swift / bow

🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
https://bow-swift.io
Other
645 stars 32 forks source link

["Request"] Add extract and embed properties to Prism #603

Closed ferranpujolcamins closed 4 years ago

ferranpujolcamins commented 4 years ago

Description

Bow offers the possibility to create a Prism providing an extract and an embed functions. For consistency, Prism should allow such functions to be retrieved from a Prism.

It might help people who is not used to the Either formulation of Prisms.

Potential implementation

public extension Prism where S == T, A == B {
    var extract: (S) -> A? {
        getOrModify >>> \.orNil
    }

    var embed: (A) -> S {
        reverseGet
    }
}

Modules

Optics

truizlop commented 4 years ago

LGTM, please open a PR with that. There is a way of creating a Prism with embed and extract, but not a way of retrieving these properties.