Some simple CasePaths extensions.
Useful to use in if conditions:
let state = Authentication.authenticated(accessToken: "123")
if (/Authentication.unauthenticated).matches(state) {
print("unauthenticated")
} else {
print("you're in!")
}As with Optional.map it transforms a value only if the enum is of the expected case.
let userIn = Authentication.authenticated(accessToken: "123")
let userOut = Authentication.unauthenticated
(/Authentication.authenticated).map(userIn, { $0.count }) // 3
((/Authentication.authenticated).map(userOut, { $0.count }) // nilSimilar to map but instead of returning any new type, it returns a new enum with a transformed value, only if the enum case matches.
(/Authentication.authenticated).mutate(userIn, { ">>\($0)<<" })
// returns Authentication.authenticated(accessToken: ">>123<<")Alejandro Martinez | http://alejandromp.com | @alexito4