From 157fc7bf727ee26056b7125aed4212e9af8b5bdb Mon Sep 17 00:00:00 2001 From: Ivan Jager Date: Thu, 27 Jun 2019 16:21:11 -0500 Subject: [PATCH] Fix broken test It would be nice if we had a better way of handling "decoders" that can't fail --- samples/SelfContained.tmpl | 2 +- src/Ccap/Codegen/Runtime.purs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/SelfContained.tmpl b/samples/SelfContained.tmpl index 2f23ad4..a7b7a9c 100644 --- a/samples/SelfContained.tmpl +++ b/samples/SelfContained.tmpl @@ -11,7 +11,7 @@ module SelfContained { type Bunnies: wrap Int type County: { diff --git a/src/Ccap/Codegen/Runtime.purs b/src/Ccap/Codegen/Runtime.purs index 2ea03c5..6d42fb7 100644 --- a/src/Ccap/Codegen/Runtime.purs +++ b/src/Ccap/Codegen/Runtime.purs @@ -99,12 +99,15 @@ codec_custom -> Codec a t codec_custom decode encode = composeCodec { decode, encode } +decodeNewtype :: forall t a. Newtype t a => a -> Either String t +decodeNewtype a = Right $ wrap a + codec_newtype :: forall t a b . Newtype t b => Codec a b -> Codec a t codec_newtype = composeCodec - { decode: Right <<< wrap + { decode: decodeNewtype , encode: unwrap }