Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Sources/CasePathsCore/Documentation.docc/CasePathsCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ macro, and is automatically imported when you `import CasePaths`
See the [`CasePaths`](../casepaths) module for information about the `@CasePathable` macro and
other non-core functionality.

To use Case paths without relying on the `@CasePathable` macro import `CasePathsCore` and manually conform your type to the `CasePathable` protocol.

For example the `Result` type is extended to be case-pathable with the following extension:

```swift
import CasePathsCore

extension Result: CasePathable {
public struct AllCasePaths {
var success: AnyCasePath<Result, Success> {
AnyCasePath(
embed: { .success($0) },
extract: {
guard case let .success(value) = $0 else { return nil }
return value
}
)
}

var failure: AnyCasePath<Result, Failure> {
AnyCasePath(
embed: { .failure($0) },
extract: {
guard case let .failure(value) = $0 else { return nil }
return value
}
)
}
}

public static var allCasePaths: AllCasePaths { AllCasePaths() }
}
```

## Topics

### Creating case paths
Expand Down