Skip to content

Commit

Permalink
explicitly state function parameters and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
cbowling committed Jul 12, 2024
1 parent 028cbbb commit 3ae39dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
],
"warnings": {
"error": "+101"
},
"uncurried": false
}
}
12 changes: 5 additions & 7 deletions src/Xml_Decode.res
Original file line number Diff line number Diff line change
Expand Up @@ -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<option<'a>>, 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
}
Expand Down
28 changes: 14 additions & 14 deletions src/Xml_Decode.resi
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ let namespace: Xml_Element.t => option<string>

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

let requireSome: option<'a> => 'a
let requireName: (Xml_Element.t, string) => Xml_Element.t
let requireNamespace: (Xml_Element.t, option<string>) => Xml_Element.t

let attribute: (~namespace: string=?, string) => decoder<string>
let attribute: (~namespace: string=?, string, Xml_Element.t) => string

let withName: (string, decoder<'a>) => decoder<'a>
let withNamespace: (option<string>, decoder<'a>) => decoder<'a>
let optional: decoder<'a> => decoder<option<'a>>
let withName: (string, decoder<'a>, Xml_Element.t) => 'a
let withNamespace: (option<string>, 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>=?, string, Xml_Element.t) => bool

let child: (Xml_Element.t => bool, decoder<'a>) => decoder<'a>
let children: (Xml_Element.t => bool, decoder<'a>) => decoder<array<'a>>
let map: (decoder<'a>, 'a => 'b) => decoder<'b>
let mapOptional: (decoder<option<'a>>, 'a => 'b) => decoder<option<'b>>
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>> => 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<option<'a>>, '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<decoder<'a>>, Xml_Element.t) => 'a

let float: string => float
let int: string => int
Expand Down

0 comments on commit 3ae39dd

Please sign in to comment.