From 3ae39dd04148cfebb7dc7d0716ed3f7ffbbc683f Mon Sep 17 00:00:00 2001 From: Chris Bowling Date: Fri, 12 Jul 2024 16:13:44 -0400 Subject: [PATCH] explicitly state function parameters and return types --- rescript.json | 3 +-- src/Xml_Decode.res | 12 +++++------- src/Xml_Decode.resi | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/rescript.json b/rescript.json index 94f76c3..54992d1 100644 --- a/rescript.json +++ b/rescript.json @@ -16,6 +16,5 @@ ], "warnings": { "error": "+101" - }, - "uncurried": false + } } diff --git a/src/Xml_Decode.res b/src/Xml_Decode.res index ff5e020..9b6c0db 100644 --- a/src/Xml_Decode.res +++ b/src/Xml_Decode.res @@ -128,25 +128,23 @@ let children = (selector: Xml_Element.t => bool, decoder: decoder<'a>, element: ->Xml_NodeList.asArrayLike ->Belt.Array.keepMap(Xml_Node.asElement) ->Belt.Array.keep(selector) - ->Belt.Array.map(decoder) + ->Belt.Array.map(decoder(_)) } let map = (decoder: decoder<'a>, f: 'a => 'b, elem) => decoder(elem)->f let mapOptional = (decoder: decoder>, f: 'a => 'b, elem) => - decoder(elem)->Belt.Option.map(f) + decoder(elem)->Option.map(f) -let andThen = (decoder: decoder<'a>, f: 'a => decoder<'b>, elem) => { - let a = decoder(elem) - f(a, elem) -} +let andThen = (decoder: decoder<'a>, f: 'a => decoder<'b>, elem) => + decoder(elem)->f let either = (left: decoder<'a>, right: decoder<'a>, elem: Xml_Element.t) => try left(elem) catch { | DecodeError(_) => right(elem) } -let withDefault = (decoder, default, elem: Xml_Element.t) => +let withDefault = (decoder: decoder<'a>, default, elem: Xml_Element.t) => try decoder(elem) catch { | DecodeError(_) => default } diff --git a/src/Xml_Decode.resi b/src/Xml_Decode.resi index c9a6878..a7bbe9d 100644 --- a/src/Xml_Decode.resi +++ b/src/Xml_Decode.resi @@ -10,8 +10,8 @@ let namespace: Xml_Element.t => option let name: Xml_Element.t => string -let ok: 'a => decoder<'a> -let error: string => decoder<'a> +let ok: ('a, Xml_Element.t) => 'a +let error: (string, Xml_Element.t) => string // require* functions throws DecodeError, can be used in custom decoders @@ -19,25 +19,25 @@ let requireSome: option<'a> => 'a let requireName: (Xml_Element.t, string) => Xml_Element.t let requireNamespace: (Xml_Element.t, option) => Xml_Element.t -let attribute: (~namespace: string=?, string) => decoder +let attribute: (~namespace: string=?, string, Xml_Element.t) => string -let withName: (string, decoder<'a>) => decoder<'a> -let withNamespace: (option, decoder<'a>) => decoder<'a> -let optional: decoder<'a> => decoder> +let withName: (string, decoder<'a>, Xml_Element.t) => 'a +let withNamespace: (option, decoder<'a>, Xml_Element.t) => 'a +let optional: (decoder<'a>, Xml_Element.t) => option<'a> // select* functions are used in 'child' and 'children' decoders let selectAny: Xml_Element.t => bool let select: (~namespace: option=?, string, Xml_Element.t) => bool -let child: (Xml_Element.t => bool, decoder<'a>) => decoder<'a> -let children: (Xml_Element.t => bool, decoder<'a>) => decoder> -let map: (decoder<'a>, 'a => 'b) => decoder<'b> -let mapOptional: (decoder>, 'a => 'b) => decoder> -let andThen: (decoder<'a>, 'a => decoder<'b>) => decoder<'b> -let either: (decoder<'a>, decoder<'a>) => decoder<'a> -let withDefault: (Xml_Element.t => 'a, 'a) => decoder<'a> -let oneOf: list> => decoder<'a> +let child: (Xml_Element.t => bool, decoder<'a>, Xml_Element.t) => 'a +let children: (Xml_Element.t => bool, decoder<'a>, Xml_Element.t) => array<'a> +let map: (decoder<'a>, 'a => 'b, Xml_Element.t) => 'b +let mapOptional: (decoder>, 'a => 'b, Xml_Element.t) => option<'b> +let andThen: (decoder<'a>, 'a => decoder<'b>, Xml_Element.t) => decoder<'b> +let either: (decoder<'a>, decoder<'a>, Xml_Element.t) => 'a +let withDefault: (decoder<'a>, 'a, Xml_Element.t) => 'a +let oneOf: (list>, Xml_Element.t) => 'a let float: string => float let int: string => int