fmap ( \eachSheet -> case (eachSheet ^. sProperties) of
Just sheetProperties -> case (sheetProperties ^. sTitle) of
Just sheets -> (sheetProperties ^. sSheetId)
Nothing -> Nothing
Nothing -> Nothing ) listOfSheets
any better way to this then case matching
The particular pattern
case f foo of
Just bla -> case g bla of
Just muh -> h muh
Nothing -> Nothing
is chararacteristic of the Maybe
monad. That instance is defined as
instance Monad Maybe where
return = Just
Nothing >>= _ = Nothing
Just x >>= f = f x
So you can rewrite the above case
construction to
f foo >>= \bla -> g bla >>= \muh -> h muh
which can be made more readable by either using do
syntax
do
bla <- f foo
muh <- g bla
h muh
or eta-reduction and the Kleisli-composition operator
(f >=> g >=> h) foo
In your example, the latter is actually not possible because the innermost function doesn't use sheets
but sheetProperties
again, but do
notation can still be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With