私はしばしば、「たぶん何もない someFunc」パターンを持つコードを持っています:
instance FromJSON SaveSection where
parseJSON (Object o) =
SaveSection <$>
o .:? "eventId" <*>
(maybe Nothing parseUSDate <$> o .:? "eventDate") <*>
o .:? "eventRecId" <*>
o .:? "idxId" <*>
(maybe Nothing parseUSDate <$> o .:? "idxDate") <*>
o .:? "idxRecId"
ここparseUSDate
に type がありText -> Maybe Date
ます。
Aeson 解析は明らかに を返しますMaybe Text
。
だから私はここの2つの層を持ち上げる必要があるように私には見えMaybe
ます. maybe Nothing someFunc
そして、パターン以外の方法でそれを行う方法がわかりません。
ここで使用できる明らかな「平坦化」またはその他の機能が不足していますか?
編集:アレクセイの答えをありがとう。
これはまさに私が探していたものです。最終結果は次のとおりです。
instance FromJSON SaveSection where
parseJSON (Object o) =
SaveSection <$>
o .:? "eventId" <*>
((>>= parseUSDate) <$> o .:? "eventDate") <*>
o .:? "eventRecId" <*>
o .:? "idxId" <*>
((>>= parseUSDate) <$> o .:? "idxDate") <*>
o .:? "idxRecId"