Combinators for navigating deeply-hierarchial 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 (becuase 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 schooch 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 qqqqqq, just easier to read
same as qqqqqqq, just easier to read
same as qqqqqqqq, just easier to read
same as qqqqqqqqq, just easier to read
same as qqqqqqqqqq, just easier to read
same as qqqqqqqqqqq, just easier to read
lift an accessor function
a -> bto a "q" (i.e.,a -> Maybe b)