doc[type]

This commit is contained in:
vegowotenks 2025-08-22 11:17:53 +02:00
parent bda145f8f4
commit b081a2fa09

View file

@ -85,6 +85,8 @@ isObject = \case
Object _ -> True Object _ -> True
_ -> False _ -> False
-- | Find the type of a value.
infer :: Json.Value -> Type infer :: Json.Value -> Type
infer = \case infer = \case
Value.Null -> Null Value.Null -> Null
@ -107,6 +109,8 @@ instance HasField "actual" Mismatch Type where
getField :: Mismatch -> Type getField :: Mismatch -> Type
getField = (.inferred) getField = (.inferred)
-- | Compute all the differences to the expected type. Empty List means that the value is conforming.
conforms :: Type -> Json.Value -> [Mismatch] conforms :: Type -> Json.Value -> [Mismatch]
conforms = conforms' [] conforms = conforms' []
@ -135,6 +139,8 @@ conforms' path layout value = case (value, layout) of
else Foldable.concatMap id mismatches else Foldable.concatMap id mismatches
_ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path} _ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path}
-- | Choose any arbitrary value conforming to the type.
sample :: Type -> Gen Value sample :: Type -> Gen Value
sample = \case sample = \case
All -> arbitrary All -> arbitrary