Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexito4/casepaths-extensions
Some simple CasePaths extensions
https://github.com/alexito4/casepaths-extensions
keypath package swift
Last synced: 1 day ago
JSON representation
Some simple CasePaths extensions
- Host: GitHub
- URL: https://github.com/alexito4/casepaths-extensions
- Owner: alexito4
- License: mit
- Created: 2020-02-11T08:37:02.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T11:13:39.000Z (about 4 years ago)
- Last Synced: 2024-11-08T21:24:08.707Z (about 2 months ago)
- Topics: keypath, package, swift
- Language: Swift
- Size: 5.86 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CasePaths-Extensions
Some simple [CasePaths](https://github.com/pointfreeco/swift-case-paths) extensions.
# matches
Useful to use in `if` conditions:
```swift
let state = Authentication.authenticated(accessToken: "123")if (/Authentication.unauthenticated).matches(state) {
print("unauthenticated")
} else {
print("you're in!")
}
```# map
As with `Optional.map` it transforms a value only if the enum is of the expected case.
```swift
let userIn = Authentication.authenticated(accessToken: "123")
let userOut = Authentication.unauthenticated(/Authentication.authenticated).map(userIn, { $0.count }) // 3
((/Authentication.authenticated).map(userOut, { $0.count }) // nil
```# mutate
Similar to `map` but instead of returning any new type, it returns a new enum with a transformed value, only if the enum case matches.
```swift
(/Authentication.authenticated).mutate(userIn, { ">>\($0)<<" })
// returns Authentication.authenticated(accessToken: ">>123<<")```
# Author
Alejandro Martinez | http://alejandromp.com | [@alexito4](https://twitter.com/alexito4)