1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 04:41:47 +03:00

Use fromMaybes to clean up the FromJSON instance for BlobPair.

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

View File

@ -105,11 +105,7 @@ instance FromJSON BlobPair where
parseJSON = withObject "BlobPair" $ \o -> do
before <- o .:? "before"
after <- o .:? "after"
case (before, after) of
(Just b, Just a) -> pure $ Compare b a
(Just b, Nothing) -> pure $ Delete b
(Nothing, Just a) -> pure $ Insert a
_ -> Prelude.fail "Expected object with 'before' and/or 'after' keys only"
maybeM (Prelude.fail "Expected object with 'before' and/or 'after' keys only") (fromMaybes before after)
maybeBlobPair :: MonadFail m => Maybe Blob -> Maybe Blob -> m BlobPair
maybeBlobPair a b = case (a, b) of