Function extract(_:)
@available(*, deprecated, message: "Use case path literal syntax (e.g., '/Root.caseName')")
public func extract<Root, Value>(_ embed: @escaping (Value) -> Root) -> (Root) -> Value?
Returns a function that can attempt to extract associated values from the given enum case initializer.
Use this function to create new transform functions to pass to higher-order methods like
compactMap
:
[Result<Int, Error>.success(42), .failure(MyError()]
.compactMap(extract(Result.success))
// [42]
Parameters
Name | Type | Description |
---|---|---|
embed | @escaping (Value) -> Root |
An enum case initializer. |
Returns
A function that can attempt to extract associated values from an enum.
@available(*, deprecated, message: "Use case path literal syntax (e.g., '/Root.caseName')")
public func extract<Root, Value>(_ embed: @escaping (Value) -> Root?) -> (Root?) -> Value?
Returns a function that can attempt to extract associated values from the given enum case initializer.
Use this function to create new transform functions to pass to higher-order methods like
compactMap
:
[Result<Int, Error>.success(42), .failure(MyError()]
.compactMap(extract(Result.success))
// [42]
Parameters
Name | Type | Description |
---|---|---|
embed | @escaping (Value) -> Root? |
An enum case initializer. |
Returns
A function that can attempt to extract associated values from an enum.