Combinators for navigating deeply-hierarchical nested values with optional properties.
The Q module is specialized to operating on values that are a Maybe a.
import Dict
import Q
import Time
type alias User =
{ profile :
Maybe
{ authProvider : Maybe String
, signInHistory :
Result (List Time.Posix) (List Time.Posix)
}
}
users : Dict.Dict Int User
users =
Dict.fromList []
toAuthProvider : Int -> Maybe String
toAuthProvider i =
Q.qq .profile .authProvider <| Dict.get i users
toLastSignInSuccess : Int -> Maybe Time.Posix
toLastSignInSuccess i =
Q.qqq .profile (Q.ope .signInHistory) List.head <|
Dict.get i usersFor when you need to scooch right past an error (because you can't dip it in ranch).
toLastSignInSuccess : Int -> Maybe Time.Posix
toLastSignInSuccess i =
qqq .profile (ope .signInHistory) List.head <|
Dict.get i usersFor when you need to scooch right past a success.
-- Get the error message if sign in failed
qq .profile (nope .signInHistory) user == Just "rate limited"It's literally just Maybe.andThen.
Apply two "and-then-able" functions in order to a Maybe a.
Apply three "and-then-able" functions in order to a Maybe a.
Apply four "and-then-able" functions in order to a Maybe a.
Apply five "and-then-able" functions in order to a Maybe a.
Apply six "and-then-able" functions in order to a Maybe a.
Apply seven "and-then-able" functions in order to a Maybe a.
Apply eight "and-then-able" functions in order to a Maybe a.
Apply nine "and-then-able" functions in order to a Maybe a.
Apply ten "and-then-able" functions in order to a Maybe a.
Apply eleven "and-then-able" functions in order to a Maybe a.
Same as Q.qqqq, just easier to read.
Same as Q.qqqqq, jsut easier to read.
Same as Q.qqqqqq, just easier to read.
Same as Q.qqqqqqq, just easier to read.
Same as Q.qqqqqqqq, just easier to read.
Same as Q.qqqqqqqqq, just easier to read.
Same as Q.qqqqqqqqqq, just easier to read.
Same as Q.qqqqqqqqqqq, just easier to read.
Lift an accessor function
a -> bto a "q" (i.e.,a -> Maybe b).