From efe5e92bfb67951efb2d41fff3a574b95da7bdb4 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Fri, 27 Jul 2018 16:52:55 +0200 Subject: [PATCH] refactor: Import <|> in the Deserialize derive --- tests/pass/serialization/de.glu | 2 +- vm/src/derive.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/pass/serialization/de.glu b/tests/pass/serialization/de.glu index e4a71050c4..3620509c71 100644 --- a/tests/pass/serialization/de.glu +++ b/tests/pass/serialization/de.glu @@ -2,7 +2,6 @@ let result @ { Result, ? } = import! std.result let de @ { Deserializer, ValueDeserializer, Deserialize, field, deserializer, ? } = import! std.serialization.de let { Test, run, assert, assert_eq, test, group, ? } = import! std.test let { Applicative, (*>) } = import! std.applicative -let { (<|>) } = import! std.alternative let { map } = import! std.functor let { (<|) } = import! std.function let int = import! std.int @@ -30,6 +29,7 @@ group "de" [ assert_eq (de.deserialize deserializer r#"{ "record" : { "y" : "abc", "x" : 1 }, "y" : 1 } "#) (Ok { record = { x = 1 }, y = 1.0 }), group "alternative" ( + let { (<|>) } = import! std.alternative let d : ValueDeserializer _ = de.int <|> map (\s -> result.unwrap_ok (int.parse s)) de.string [ diff --git a/vm/src/derive.rs b/vm/src/derive.rs index 896304004b..d3b5421ba3 100644 --- a/vm/src/derive.rs +++ b/vm/src/derive.rs @@ -695,6 +695,7 @@ fn generate_deserialize( ); let functor_import = generate_import(span, symbols, &[], &["map"], "std.functor"); let applicative_import = generate_import(span, symbols, &[], &["<*>"], "std.applicative"); + let alternative_import = generate_import(span, symbols, &[], &["<|>"], "std.alternative"); let deserializer_binding = ValueBinding { name: pos::spanned(span, Pattern::Ident(deserializer_fn.clone())), @@ -726,6 +727,7 @@ fn generate_deserialize( serialization_import, functor_import, applicative_import, + alternative_import, deserializer_binding, ].into_iter() .rev()