From ba37cd65e96a96e96807dd382d979fbde0bb63d5 Mon Sep 17 00:00:00 2001 From: Tom Sydney Kerckhove Date: Mon, 15 Nov 2021 10:52:16 +0100 Subject: [PATCH] more docs about bimap --- autodocodec/src/Autodocodec/Codec.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/autodocodec/src/Autodocodec/Codec.hs b/autodocodec/src/Autodocodec/Codec.hs index ae14bf7..99130b8 100644 --- a/autodocodec/src/Autodocodec/Codec.hs +++ b/autodocodec/src/Autodocodec/Codec.hs @@ -441,14 +441,12 @@ eitherCodec = EitherCodec -- -- This function allows you to have the parsing fail in a new way. -- +-- If you use this function, then you will most likely want to add documentation about how not every value that the schema specifies will be accepted. +-- -- === Example usage -- --- > boundedIntegerCodec :: (Integral i, Bounded i) => JSONCodec i --- > boundedIntegerCodec = bimapCodec go fromIntegral $ NumberCodec Nothing --- > where --- > go s = case Scientific.toBoundedInteger s of --- > Nothing -> Left $ "Number too big: " <> show s --- > Just i -> Right i +-- logLevelCodec :: JSONCodec LogLevel +-- logLevelCodec = bimapCodec parseLogLevel renderLogLevel codec "Valid values include DEBUG, INFO, WARNING, ERROR." bimapCodec :: (oldOutput -> Either String newOutput) -> (newInput -> oldInput) ->