what can i use instead of `case of` to reduce the code?

  • A+
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

What you here bascially show is the use of a Maybe monad, so we can write it like:

fmap (/s -> (s ^. sProperties) >>= /sheetProperties -> (sheetProperties ^. sTitle) >> (sheetProperties ^. sSheetId)) listOfSheets 

Since a Maybe monad is defined as:

instance Monad Maybe where     return = Just     (>>=) Nothing _ = Nothing     (>>=) (Just x) f = f x 

Or we can write it in do notation, although that is basically the same:

fmap f listOfSheets     where f eachSheet = do         sheetProperties <- eachSheet ^. sProperties         sheets <- sheetProperties ^. sTitle         sheetProperties ^. sSheetId 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: