checklist icon indicating copy to clipboard operation
checklist copied to clipboard

Parsing Lib Integrations?

Open Jacoby6000 opened this issue 7 years ago • 1 comments

I think it'd be very helpful to provide integrations with json/xml/ parsing libs. Ideally we'd provide a function decoder a -> validator a b -> decoder b. This way users can transparently use checklist for validation during parsing.

Example for something like circe:

def validatingDecoder[A, B](
  handleWarnings: (WarningMessages, B) => DecodeResult[B])(
  implicit decoder: Decoder[A], validator: Validator[A, B]
): Decoder[B] = 
  decoder.emap(validator.validate(_).fold(
    handleErrors = validatorErrorToCirceError,
    handleWarnings = handleWarnings,
    handleSuccess = DecodeResult.success(_)
  ))

Jacoby6000 avatar Jan 29 '18 15:01 Jacoby6000

Tighter integrations than the one above could reduce overhead a bit, but I think the above is a good first-pass.

Jacoby6000 avatar Jan 29 '18 16:01 Jacoby6000