Skip to content

Commit

Permalink
refactor: Import <|> in the Deserialize derive
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jul 27, 2018
1 parent 09a79f4 commit efe5e92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/pass/serialization/de.glu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[
Expand Down
2 changes: 2 additions & 0 deletions vm/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -726,6 +727,7 @@ fn generate_deserialize(
serialization_import,
functor_import,
applicative_import,
alternative_import,
deserializer_binding,
].into_iter()
.rev()
Expand Down

0 comments on commit efe5e92

Please sign in to comment.