1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 20:31:55 +03:00

Use Applicative to tidy up further.

This commit is contained in:
Rob Rix 2019-10-18 12:25:40 -04:00
parent fecb0d8f1f
commit 41f38b1c59
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -102,10 +102,9 @@ noLanguageForBlob blobPath = throwError (SomeException (NoLanguageForBlob blobPa
type BlobPair = Edit Blob Blob
instance FromJSON BlobPair where
parseJSON = withObject "BlobPair" $ \o -> do
before <- o .:? "before"
after <- o .:? "after"
maybeM (Prelude.fail "Expected object with 'before' and/or 'after' keys only") (fromMaybes before after)
parseJSON = withObject "BlobPair" $ \o ->
fromMaybes <$> (o .:? "before") <*> (o .:? "after")
>>= maybeM (Prelude.fail "Expected object with 'before' and/or 'after' keys only")
maybeBlobPair :: MonadFail m => Maybe Blob -> Maybe Blob -> m BlobPair
maybeBlobPair a b = case (a, b) of