diff --git a/belt-cppo/belt_Set.cppo.res b/belt-cppo/belt_Set.cppo.res index 2ef4124..9b649f8 100644 --- a/belt-cppo/belt_Set.cppo.res +++ b/belt-cppo/belt_Set.cppo.res @@ -20,17 +20,11 @@ let maximum = N.maximum let maxUndefined = N.maxUndefined let forEach = N.forEach -let forEachU = N.forEachU let reduce = N.reduce -let reduceU = N.reduceU let every = N.every -let everyU = N.everyU let some = N.some -let someU = N.someU let keep = N.keepShared -let keepU = N.keepSharedU let partition = N.partitionShared -let partitionU = N.partitionSharedU let size = N.size let toList = N.toList @@ -231,3 +225,10 @@ let rec diff = (s1: t, s2: t) => N.joinShared(ll, v1, rr) } } + +let forEachU = forEach +let reduceU = reduce +let everyU = every +let someU = some +let keepU = keep +let partitionU = partition diff --git a/belt-cppo/belt_Set.cppo.resi b/belt-cppo/belt_Set.cppo.resi index ab3719d..d390940 100644 --- a/belt-cppo/belt_Set.cppo.resi +++ b/belt-cppo/belt_Set.cppo.resi @@ -90,6 +90,7 @@ equal elements. */ let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** @@ -97,11 +98,13 @@ let forEachU: (t, value => unit) => unit */ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -110,6 +113,7 @@ unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -118,6 +122,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -125,6 +130,7 @@ let keepU: (t, value => bool) => t */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt-cppo/hashmap.cppo.res b/belt-cppo/hashmap.cppo.res index e5de8ed..d0d4c4d 100644 --- a/belt-cppo/hashmap.cppo.res +++ b/belt-cppo/hashmap.cppo.res @@ -191,12 +191,9 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats -let keepMapInPlaceU = N.keepMapInPlaceU let keepMapInPlace = N.keepMapInPlace let toArray = N.toArray let copy = N.copy @@ -223,3 +220,7 @@ let mergeMany = (h, arr) => { set(h, k, v) } } + +let forEachU = forEach +let reduceU = reduce +let keepMapInPlaceU = keepMapInPlace diff --git a/belt-cppo/hashmap.cppo.resi b/belt-cppo/hashmap.cppo.resi index 7939741..d0e1226 100644 --- a/belt-cppo/hashmap.cppo.resi +++ b/belt-cppo/hashmap.cppo.resi @@ -27,12 +27,15 @@ let has: (t<'b>, key) => bool let remove: (t<'a>, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t<'b>, (key, 'b) => unit) => unit let forEach: (t<'b>, (key, 'b) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c let reduce: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c +@deprecated("Use `keepMapInPlace` instead") let keepMapInPlaceU: (t<'a>, (key, 'a) => option<'a>) => unit let keepMapInPlace: (t<'a>, (key, 'a) => option<'a>) => unit diff --git a/belt-cppo/hashset.cppo.res b/belt-cppo/hashset.cppo.res index af73488..4ddfadf 100644 --- a/belt-cppo/hashset.cppo.res +++ b/belt-cppo/hashset.cppo.res @@ -136,9 +136,7 @@ let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats let toArray = N.toArray @@ -162,3 +160,6 @@ let mergeMany = (h, arr) => { add(h, A.getUnsafe(arr, i)) } } + +let forEachU = forEach +let reduceU = reduce diff --git a/belt-cppo/hashset.cppo.resi b/belt-cppo/hashset.cppo.resi index 429fcc9..6b2b842 100644 --- a/belt-cppo/hashset.cppo.resi +++ b/belt-cppo/hashset.cppo.resi @@ -55,9 +55,11 @@ let has: (t, key) => bool let remove: (t, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t, key => unit) => unit let forEach: (t, key => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'c, ('c, key) => 'c) => 'c let reduce: (t, 'c, ('c, key) => 'c) => 'c diff --git a/belt-cppo/internal_map.cppo.res b/belt-cppo/internal_map.cppo.res index dae22e1..407d3c5 100644 --- a/belt-cppo/internal_map.cppo.res +++ b/belt-cppo/internal_map.cppo.res @@ -174,7 +174,7 @@ let split = (x: key, n) => | Some(n) => splitAux(x, n) } -let rec mergeU = (s1, s2, f) => +let rec merge = (s1, s2, f) => switch (s1, s2) { | (None, None) => None | (Some(n) /* (Node (l1, v1, d1, r1, h1), _) */, _) @@ -185,16 +185,14 @@ let rec mergeU = (s1, s2, f) => } => let {N.left: l1, key: v1, value: d1, right: r1} = n let (l2, d2, r2) = split(v1, s2) - N.concatOrJoin(mergeU(l1, l2, f), v1, f(v1, Some(d1), d2), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v1, f(v1, Some(d1), d2), merge(r1, r2, f)) | (_, Some(n)) /* Node (l2, v2, d2, r2, h2) */ => let {N.left: l2, key: v2, value: d2, right: r2} = n let (l1, d1, r1) = split(v2, s1) - N.concatOrJoin(mergeU(l1, l2, f), v2, f(v2, d1, Some(d2)), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v2, f(v2, d1, Some(d2)), merge(r1, r2, f)) | _ => assert(false) } -let merge = (s1, s2, f) => mergeU(s1, s2, (a, b, c) => f(a, b, c)) - let rec compareAux = (e1, e2, vcmp) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -212,7 +210,7 @@ let rec compareAux = (e1, e2, vcmp) => | (_, _) => 0 } -let cmpU = (s1, s2, cmp) => { +let cmp = (s1, s2, cmp) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { compareAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), cmp) @@ -223,8 +221,6 @@ let cmpU = (s1, s2, cmp) => { } } -let cmp = (s1, s2, f) => cmpU(s1, s2, (a, b) => f(a, b)) - let rec eqAux = (e1, e2, eq) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -236,7 +232,7 @@ let rec eqAux = (e1, e2, eq) => | (_, _) => true } /* end */ -let eqU = (s1, s2, eq) => { +let eq = (s1, s2, eq) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { eqAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), eq) @@ -245,8 +241,6 @@ let eqU = (s1, s2, eq) => { } } -let eq = (s1, s2, f) => eqU(s1, s2, (a, b) => f(a, b)) - let rec addMutate = (t: t<_>, x, data): t<_> => switch t { | None => N.singleton(x, data) @@ -275,7 +269,7 @@ let fromArray = (xs: array<(key, _)>) => { if len == 0 { None } else { - let next = ref(S.strictlySortedLengthU(xs, ((x0, _), (y0, _)) => x0 < y0)) + let next = ref(S.strictlySortedLength(xs, ((x0, _), (y0, _)) => x0 < y0)) let result = ref( if next.contents >= 0 { @@ -292,3 +286,7 @@ let fromArray = (xs: array<(key, _)>) => { result.contents } } + +let cmpU = cmp +let eqU = eq +let mergeU = merge diff --git a/belt-cppo/map.cppo.res b/belt-cppo/map.cppo.res index 6afc30b..6dbae01 100644 --- a/belt-cppo/map.cppo.res +++ b/belt-cppo/map.cppo.res @@ -25,21 +25,14 @@ let minimum = N.minimum let minUndefined = N.minUndefined let maximum = N.maximum let maxUndefined = N.maxUndefined -let forEachU = N.forEachU +let findFirstBy = N.findFirstBy let forEach = N.forEach -let mapU = N.mapU let map = N.map -let mapWithKeyU = N.mapWithKeyU let mapWithKey = N.mapWithKey -let reduceU = N.reduceU let reduce = N.reduce -let everyU = N.everyU let every = N.every -let someU = N.someU let some = N.some -let keepU = N.keepSharedU let keep = N.keepShared -let partitionU = N.partitionSharedU let partition = N.partitionShared let size = N.size let toList = N.toList @@ -65,7 +58,7 @@ let rec set = (t, newK: key, newD: _) => } } -let rec updateU = (t, x: key, f) => +let rec update = (t, x: key, f) => switch t { | None => switch f(None) { @@ -91,14 +84,14 @@ let rec updateU = (t, x: key, f) => } else { let {N.left: l, right: r, value: v} = n if x < k { - let ll = updateU(l, x, f) + let ll = update(l, x, f) if l === ll { t } else { N.bal(ll, k, v, r) } } else { - let rr = updateU(r, x, f) + let rr = update(r, x, f) if r === rr { t } else { @@ -108,8 +101,6 @@ let rec updateU = (t, x: key, f) => } } -let update = (t, x, f) => updateU(t, x, a => f(a)) - let rec removeAux = (n, x: key) => { let {N.left: l, key: v, right: r} = n if x == v { @@ -169,9 +160,6 @@ let removeMany = (t, keys) => { } } -let findFirstByU = N.findFirstByU -let findFirstBy = N.findFirstBy - let mergeMany = (h, arr) => { let len = A.length(arr) let v = ref(h) @@ -185,15 +173,26 @@ let mergeMany = (h, arr) => { /* let mergeArray = mergeMany */ let has = I.has -let cmpU = I.cmpU let cmp = I.cmp -let eqU = I.eqU let eq = I.eq let get = I.get let getUndefined = I.getUndefined let getWithDefault = I.getWithDefault let getExn = I.getExn let split = I.split -let mergeU = I.mergeU let merge = I.merge let fromArray = I.fromArray + +let cmpU = cmp +let eqU = eq +let everyU = every +let findFirstByU = findFirstBy +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithKeyU = mapWithKey +let mergeU = merge +let partitionU = partition +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt-cppo/map.cppo.resi b/belt-cppo/map.cppo.resi index f3df600..e82b18c 100644 --- a/belt-cppo/map.cppo.resi +++ b/belt-cppo/map.cppo.resi @@ -15,9 +15,11 @@ let isEmpty: t<'v> => bool let has: (t<'v>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'v>, t<'v>, ('v, 'v) => int) => int let cmp: (t<'v>, t<'v>, ('v, 'v) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'v>, t<'v>, ('v, 'v) => bool) => bool /** @@ -27,6 +29,7 @@ equal data. */ let eq: (t<'v>, t<'v>, ('v, 'v) => bool) => bool +@deprecated("Use `findFirstBy` instead") let findFirstByU: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> /** @@ -40,6 +43,7 @@ findFirstBy(s0, (k, v) => k == 4) == option((4, "4")) */ let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> +@deprecated("Use `forEach` instead") let forEachU: (t<'v>, (key, 'v) => unit) => unit /** @@ -50,6 +54,7 @@ order with respect to the ordering over the type of the keys. */ let forEach: (t<'v>, (key, 'v) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 /** @@ -59,6 +64,7 @@ where `k1 ... kN` are the keys of all bindings in `m` */ let reduce: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 +@deprecated("Use `every` instead") let everyU: (t<'v>, (key, 'v) => bool) => bool /** @@ -66,6 +72,7 @@ let everyU: (t<'v>, (key, 'v) => bool) => bool Order unspecified */ let every: (t<'v>, (key, 'v) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'v>, (key, 'v) => bool) => bool /** @@ -128,9 +135,11 @@ in `m`, its previous binding disappears. */ let set: (t<'v>, key, 'v) => t<'v> +@deprecated("Use `update` instead") let updateU: (t<'v>, key, option<'v> => option<'v>) => t<'v> let update: (t<'v>, key, option<'v> => option<'v>) => t<'v> +@deprecated("Use `merge` instead") let mergeU: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c> /** @@ -142,6 +151,7 @@ let merge: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c let mergeMany: (t<'v>, array<(key, 'v)>) => t<'v> +@deprecated("Use `keep` instead") let keepU: (t<'v>, (key, 'v) => bool) => t<'v> /** @@ -150,6 +160,7 @@ let keepU: (t<'v>, (key, 'v) => bool) => t<'v> */ let keep: (t<'v>, (key, 'v) => bool) => t<'v> +@deprecated("Use `partition` instead") let partitionU: (t<'v>, (key, 'v) => bool) => (t<'v>, t<'v>) /** @@ -167,6 +178,7 @@ contains no binding for `x`, or `Some(v)` if `m` binds `v` to `x`. */ let split: (key, t<'v>) => (t<'v>, option<'v>, t<'v>) +@deprecated("Use `map` instead") let mapU: (t<'v>, 'v => 'v2) => t<'v2> /** @@ -177,5 +189,6 @@ ordering over the type of the keys. */ let map: (t<'v>, 'v => 'v2) => t<'v2> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'v>, (key, 'v) => 'v2) => t<'v2> let mapWithKey: (t<'v>, (key, 'v) => 'v2) => t<'v2> diff --git a/belt-cppo/mapm.cppo.res b/belt-cppo/mapm.cppo.res index 2797b6d..4820a22 100644 --- a/belt-cppo/mapm.cppo.res +++ b/belt-cppo/mapm.cppo.res @@ -35,18 +35,12 @@ let set = (m: t<_>, k, v) => { } } -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, (a, b) => f(a, b)) -let mapU = (d, f) => {data: N.mapU(d.data, f)} -let map = (d, f) => mapU(d, a => f(a)) -let mapWithKeyU = (d, f) => {data: N.mapWithKeyU(d.data, f)} -let mapWithKey = (d, f) => mapWithKeyU(d, (a, b) => f(a, b)) -let reduceU = (d, acc, f) => N.reduceU(d.data, acc, f) -let reduce = (d, acc, f) => reduceU(d, acc, (a, b, c) => f(a, b, c)) -let everyU = (d, f) => N.everyU(d.data, f) -let every = (d, f) => everyU(d, (a, b) => f(a, b)) -let someU = (d, f) => N.someU(d.data, f) -let some = (d, f) => someU(d, (a, b) => f(a, b)) +let forEach = (d, f) => N.forEach(d.data, f) +let map = (d, f) => {data: N.map(d.data, f)} +let mapWithKey = (d, f) => {data: N.mapWithKey(d.data, f)} +let reduce = (d, acc, f) => N.reduce(d.data, acc, f) +let every = (d, f) => N.every(d.data, f) +let some = (d, f) => N.some(d.data, f) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -133,14 +127,14 @@ let rec updateDone = (t, x: key, f) => } } -let updateU = (t, x, f) => { +let update = (t, x, f) => { let oldRoot = t.data let newRoot = updateDone(oldRoot, x, f) if newRoot !== oldRoot { t.data = newRoot } } -let update = (t, x, f) => updateU(t, x, a => f(a)) + let rec removeArrayMutateAux = (t, xs, i, len) => if i < len { let ele = A.getUnsafe(xs, i) @@ -171,13 +165,21 @@ let removeMany = (d: t<_>, xs) => { let fromArray = xs => {data: I.fromArray(xs)} -let cmpU = (d0, d1, f) => I.cmpU(d0.data, d1.data, f) -let cmp = (d0, d1, f) => cmpU(d0, d1, (a, b) => f(a, b)) +let cmp = (d0, d1, f) => I.cmp(d0.data, d1.data, f) -let eqU = (d0, d1, f) => I.eqU(d0.data, d1.data, f) -let eq = (d0, d1, f) => eqU(d0, d1, (a, b) => f(a, b)) +let eq = (d0, d1, f) => I.eq(d0.data, d1.data, f) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) let getWithDefault = (d, x, def) => I.getWithDefault(d.data, x, def) let getExn = (d, x) => I.getExn(d.data, x) + +let cmpU = cmp +let eqU = eq +let everyU = every +let forEachU = forEach +let mapU = map +let mapWithKeyU = mapWithKey +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt-cppo/mapm.cppo.resi b/belt-cppo/mapm.cppo.resi index 913e792..37f831a 100644 --- a/belt-cppo/mapm.cppo.resi +++ b/belt-cppo/mapm.cppo.resi @@ -38,6 +38,7 @@ let isEmpty: t<'a> => bool let has: (t<'a>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'a>, t<'a>, ('a, 'a) => int) => int /** @@ -46,11 +47,13 @@ value pair */ let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** `eq(m1, m2, cmp)` */ let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, (key, 'a) => unit) => unit /** @@ -59,6 +62,7 @@ first argument, and the associated value as second argument. The application order of `f` is in increasing order. */ let forEach: (t<'a>, (key, 'a) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b /** @@ -67,6 +71,7 @@ the keys of all bindings in `m` (in increasing order), and `d1 ... dN` are the associated data. */ let reduce: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b +@deprecated("Use `every` instead") let everyU: (t<'a>, (key, 'a) => bool) => bool /** @@ -75,6 +80,7 @@ The application order of `p` is unspecified. */ let every: (t<'a>, (key, 'a) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'a>, (key, 'a) => bool) => bool /** @@ -127,9 +133,11 @@ already bound in `m`, its previous binding disappears. */ let set: (t<'a>, key, 'a) => unit +@deprecated("Use `update` instead") let updateU: (t<'a>, key, option<'a> => option<'a>) => unit let update: (t<'a>, key, option<'a> => option<'a>) => unit +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => t<'b> /** @@ -139,5 +147,6 @@ to `a`. The bindings are passed to `f` in increasing order with respect to the ordering over the type of the keys. */ let map: (t<'a>, 'a => 'b) => t<'b> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'a>, (key, 'a) => 'b) => t<'b> let mapWithKey: (t<'a>, (key, 'a) => 'b) => t<'b> diff --git a/belt-cppo/setm.cppo.res b/belt-cppo/setm.cppo.res index 89c4ede..f980679 100644 --- a/belt-cppo/setm.cppo.res +++ b/belt-cppo/setm.cppo.res @@ -203,25 +203,14 @@ let mergeMany = (d, arr) => d.data = addArrayMutate(d.data, arr) let make = () => {data: None} let isEmpty = d => N.isEmpty(d.data) - let minimum = d => N.minimum(d.data) - let minUndefined = d => N.minUndefined(d.data) - let maximum = d => N.maximum(d.data) - let maxUndefined = d => N.maxUndefined(d.data) - -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, a => f(a)) - -let reduceU = (d, acc, cb) => N.reduceU(d.data, acc, cb) -let reduce = (d, acc, cb) => reduceU(d, acc, (a, b) => cb(a, b)) - -let everyU = (d, p) => N.everyU(d.data, p) -let every = (d, p) => everyU(d, a => p(a)) -let someU = (d, p) => N.someU(d.data, p) -let some = (d, p) => someU(d, a => p(a)) +let forEach = (d, f) => N.forEach(d.data, f) +let reduce = (d, acc, cb) => N.reduce(d.data, acc, cb) +let every = (d, p) => N.every(d.data, p) +let some = (d, p) => N.some(d.data, p) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -262,14 +251,12 @@ let split = (d, key) => { } } -let keepU = (d, p) => {data: N.keepCopyU(d.data, p)} -let keep = (d, p) => keepU(d, a => p(a)) +let keep = (d, p) => {data: N.keepCopy(d.data, p)} -let partitionU = (d, p) => { - let (a, b) = N.partitionCopyU(d.data, p) +let partition = (d, p) => { + let (a, b) = N.partitionCopy(d.data, p) ({data: a}, {data: b}) } -let partition = (d, p) => partitionU(d, a => p(a)) let subset = (a, b) => I.subset(a.data, b.data) let intersect = (dataa, datab) => { @@ -344,3 +331,10 @@ let union = (dataa: t, datab: t): t => { let has = (d, x) => I.has(d.data, x) let copy = d => {data: N.copy(d.data)} + +let everyU = every +let forEachU = forEach +let keepU = keep +let partitionU = partition +let reduceU = reduce +let someU = some diff --git a/belt-cppo/setm.cppo.resi b/belt-cppo/setm.cppo.resi index cdc2fb0..bbfe9a5 100644 --- a/belt-cppo/setm.cppo.resi +++ b/belt-cppo/setm.cppo.resi @@ -68,16 +68,19 @@ let subset: (t, t) => bool let cmp: (t, t) => int let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** In increasing order*/ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -85,6 +88,7 @@ let everyU: (t, value => bool) => bool Order unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -93,6 +97,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -101,6 +106,7 @@ predicate `p`. */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt/src/belt.res b/belt/src/belt.res index 333b098..7604a37 100644 --- a/belt/src/belt.res +++ b/belt/src/belt.res @@ -77,36 +77,6 @@ let greaterThan2UniqueAndSorted = Js.log2("result", greaterThan2UniqueAndSorted) ``` -## Curried vs. Uncurried Callbacks - -For functions taking a callback parameter, there are usually two versions -available: - -- curried (no suffix) -- uncurried (suffixed with `U`) - -E.g.: - -## Examples - -```rescript -let forEach: (t<'a>, 'a => unit) => unit - -let forEachU: (t<'a>, 'a => unit) => unit -``` - -The uncurried version will be faster in some cases, but for simplicity we recommend to stick with the curried version unless you need the extra performance. - -The two versions can be invoked as follows: - -## Examples - -```rescript -["a", "b", "c"]->Belt.Array.forEach(x => Js.log(x)) - -["a", "b", "c"]->Belt.Array.forEachU(x => Js.log(x)) -``` - ## Specialized Collections For collections types like set or map, Belt provides both a generic module as well as specialized, more efficient implementations for string and int keys. diff --git a/belt/src/belt_Array.js b/belt/src/belt_Array.js index 9800ea2..4fdcbd8 100644 --- a/belt/src/belt_Array.js +++ b/belt/src/belt_Array.js @@ -102,7 +102,7 @@ function make(l, f) { return res; } -function makeByU(l, f) { +function makeBy(l, f) { if (l <= 0) { return []; } @@ -113,24 +113,12 @@ function makeByU(l, f) { return res; } -function makeBy(l, f) { - return makeByU(l, (function (a) { - return f(a); - })); -} - -function makeByAndShuffleU(l, f) { - let u = makeByU(l, f); +function makeByAndShuffle(l, f) { + let u = makeBy(l, f); shuffleInPlace(u); return u; } -function makeByAndShuffle(l, f) { - return makeByAndShuffleU(l, (function (a) { - return f(a); - })); -} - function range(start, finish) { let cut = finish - start | 0; if (cut < 0) { @@ -172,7 +160,7 @@ function zip(xs, ys) { return s; } -function zipByU(xs, ys, f) { +function zipBy(xs, ys, f) { let lenx = xs.length; let leny = ys.length; let len = lenx < leny ? lenx : leny; @@ -183,12 +171,6 @@ function zipByU(xs, ys, f) { return s; } -function zipBy(xs, ys, f) { - return zipByU(xs, ys, (function (a, b) { - return f(a, b); - })); -} - function concat(a1, a2) { let l1 = a1.length; let l2 = a2.length; @@ -294,19 +276,13 @@ function blit(a1, ofs1, a2, ofs2, len) { } } -function forEachU(a, f) { +function forEach(a, f) { for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ f(a[i]); } } -function forEach(a, f) { - forEachU(a, (function (a) { - f(a); - })); -} - -function mapU(a, f) { +function map(a, f) { let l = a.length; let r = new Array(l); for(let i = 0; i < l; ++i){ @@ -315,23 +291,11 @@ function mapU(a, f) { return r; } -function map(a, f) { - return mapU(a, (function (a) { - return f(a); - })); -} - -function flatMapU(a, f) { - return concatMany(mapU(a, f)); -} - function flatMap(a, f) { - return concatMany(mapU(a, (function (a) { - return f(a); - }))); + return concatMany(map(a, f)); } -function getByU(a, p) { +function getBy(a, p) { let l = a.length; let i = 0; let r; @@ -345,13 +309,7 @@ function getByU(a, p) { return r; } -function getBy(a, p) { - return getByU(a, (function (a) { - return p(a); - })); -} - -function getIndexByU(a, p) { +function getIndexBy(a, p) { let l = a.length; let i = 0; let r; @@ -365,13 +323,7 @@ function getIndexByU(a, p) { return r; } -function getIndexBy(a, p) { - return getIndexByU(a, (function (a) { - return p(a); - })); -} - -function keepU(a, f) { +function keep(a, f) { let l = a.length; let r = new Array(l); let j = 0; @@ -387,13 +339,7 @@ function keepU(a, f) { return r; } -function keep(a, f) { - return keepU(a, (function (a) { - return f(a); - })); -} - -function keepWithIndexU(a, f) { +function keepWithIndex(a, f) { let l = a.length; let r = new Array(l); let j = 0; @@ -409,13 +355,7 @@ function keepWithIndexU(a, f) { return r; } -function keepWithIndex(a, f) { - return keepWithIndexU(a, (function (a, i) { - return f(a, i); - })); -} - -function keepMapU(a, f) { +function keepMap(a, f) { let l = a.length; let r = new Array(l); let j = 0; @@ -432,25 +372,13 @@ function keepMapU(a, f) { return r; } -function keepMap(a, f) { - return keepMapU(a, (function (a) { - return f(a); - })); -} - -function forEachWithIndexU(a, f) { +function forEachWithIndex(a, f) { for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ f(i, a[i]); } } -function forEachWithIndex(a, f) { - forEachWithIndexU(a, (function (a, b) { - f(a, b); - })); -} - -function mapWithIndexU(a, f) { +function mapWithIndex(a, f) { let l = a.length; let r = new Array(l); for(let i = 0; i < l; ++i){ @@ -459,13 +387,7 @@ function mapWithIndexU(a, f) { return r; } -function mapWithIndex(a, f) { - return mapWithIndexU(a, (function (a, b) { - return f(a, b); - })); -} - -function reduceU(a, x, f) { +function reduce(a, x, f) { let r = x; for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ r = f(r, a[i]); @@ -473,13 +395,7 @@ function reduceU(a, x, f) { return r; } -function reduce(a, x, f) { - return reduceU(a, x, (function (a, b) { - return f(a, b); - })); -} - -function reduceReverseU(a, x, f) { +function reduceReverse(a, x, f) { let r = x; for(let i = a.length - 1 | 0; i >= 0; --i){ r = f(r, a[i]); @@ -487,13 +403,7 @@ function reduceReverseU(a, x, f) { return r; } -function reduceReverse(a, x, f) { - return reduceReverseU(a, x, (function (a, b) { - return f(a, b); - })); -} - -function reduceReverse2U(a, b, x, f) { +function reduceReverse2(a, b, x, f) { let r = x; let len = Caml.int_min(a.length, b.length); for(let i = len - 1 | 0; i >= 0; --i){ @@ -502,13 +412,7 @@ function reduceReverse2U(a, b, x, f) { return r; } -function reduceReverse2(a, b, x, f) { - return reduceReverse2U(a, b, x, (function (a, b, c) { - return f(a, b, c); - })); -} - -function reduceWithIndexU(a, x, f) { +function reduceWithIndex(a, x, f) { let r = x; for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ r = f(r, a[i], i); @@ -516,13 +420,7 @@ function reduceWithIndexU(a, x, f) { return r; } -function reduceWithIndex(a, x, f) { - return reduceWithIndexU(a, x, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(arr, b) { +function every(arr, b) { let len = arr.length; let _i = 0; while(true) { @@ -538,13 +436,7 @@ function everyU(arr, b) { }; } -function every(arr, f) { - return everyU(arr, (function (b) { - return f(b); - })); -} - -function someU(arr, b) { +function some(arr, b) { let len = arr.length; let _i = 0; while(true) { @@ -560,12 +452,6 @@ function someU(arr, b) { }; } -function some(arr, f) { - return someU(arr, (function (b) { - return f(b); - })); -} - function everyAux2(arr1, arr2, _i, b, len) { while(true) { let i = _i; @@ -580,17 +466,11 @@ function everyAux2(arr1, arr2, _i, b, len) { }; } -function every2U(a, b, p) { - return everyAux2(a, b, 0, p, Caml.int_min(a.length, b.length)); -} - function every2(a, b, p) { - return every2U(a, b, (function (a, b) { - return p(a, b); - })); + return everyAux2(a, b, 0, p, Caml.int_min(a.length, b.length)); } -function some2U(a, b, p) { +function some2(a, b, p) { let _i = 0; let len = Caml.int_min(a.length, b.length); while(true) { @@ -606,13 +486,7 @@ function some2U(a, b, p) { }; } -function some2(a, b, p) { - return some2U(a, b, (function (a, b) { - return p(a, b); - })); -} - -function eqU(a, b, p) { +function eq(a, b, p) { let lena = a.length; let lenb = b.length; if (lena === lenb) { @@ -622,13 +496,7 @@ function eqU(a, b, p) { } } -function eq(a, b, p) { - return eqU(a, b, (function (a, b) { - return p(a, b); - })); -} - -function cmpU(a, b, p) { +function cmp(a, b, p) { let lena = a.length; let lenb = b.length; if (lena > lenb) { @@ -652,13 +520,7 @@ function cmpU(a, b, p) { } } -function cmp(a, b, p) { - return cmpU(a, b, (function (a, b) { - return p(a, b); - })); -} - -function partitionU(a, f) { +function partition(a, f) { let l = a.length; let i = 0; let j = 0; @@ -682,12 +544,6 @@ function partitionU(a, f) { ]; } -function partition(a, f) { - return partitionU(a, (function (x) { - return f(x); - })); -} - function unzip(a) { let l = a.length; let a1 = new Array(l); @@ -703,7 +559,7 @@ function unzip(a) { ]; } -function joinWithU(a, sep, toString) { +function joinWith(a, sep, toString) { let l = a.length; if (l === 0) { return ""; @@ -723,13 +579,7 @@ function joinWithU(a, sep, toString) { }; } -function joinWith(a, sep, toString) { - return joinWithU(a, sep, (function (x) { - return toString(x); - })); -} - -function initU(n, f) { +function init(n, f) { let v = new Array(n); for(let i = 0; i < n; ++i){ v[i] = f(i); @@ -737,11 +587,57 @@ function initU(n, f) { return v; } -function init(n, f) { - return initU(n, (function (i) { - return f(i); - })); -} +let makeByU = makeBy; + +let makeByAndShuffleU = makeByAndShuffle; + +let zipByU = zipBy; + +let forEachU = forEach; + +let mapU = map; + +let flatMapU = flatMap; + +let getByU = getBy; + +let getIndexByU = getIndexBy; + +let keepU = keep; + +let keepWithIndexU = keepWithIndex; + +let keepMapU = keepMap; + +let forEachWithIndexU = forEachWithIndex; + +let mapWithIndexU = mapWithIndex; + +let partitionU = partition; + +let reduceU = reduce; + +let reduceReverseU = reduceReverse; + +let reduceReverse2U = reduceReverse2; + +let reduceWithIndexU = reduceWithIndex; + +let joinWithU = joinWith; + +let someU = some; + +let everyU = every; + +let every2U = every2; + +let some2U = some2; + +let cmpU = cmp; + +let eqU = eq; + +let initU = init; export { get, diff --git a/belt/src/belt_Array.res b/belt/src/belt_Array.res index e83e044..5700b4b 100644 --- a/belt/src/belt_Array.res +++ b/belt/src/belt_Array.res @@ -116,7 +116,7 @@ let make = (l, f) => /* See #6575. We could also check for maximum array size, but this depends on whether we create a float array or a regular one... */ -let makeByU = (l, f) => +let makeBy = (l, f) => if l <= 0 { [] } else { @@ -127,16 +127,12 @@ let makeByU = (l, f) => res } -let makeBy = (l, f) => makeByU(l, a => f(a)) - -let makeByAndShuffleU = (l, f) => { - let u = makeByU(l, f) +let makeByAndShuffle = (l, f) => { + let u = makeBy(l, f) shuffleInPlace(u) u } -let makeByAndShuffle = (l, f) => makeByAndShuffleU(l, a => f(a)) - let range = (start, finish) => { let cut = finish - start if cut < 0 { @@ -176,7 +172,7 @@ let zip = (xs, ys) => { s } -let zipByU = (xs, ys, f) => { +let zipBy = (xs, ys, f) => { let (lenx, leny) = (length(xs), length(ys)) let len = Pervasives.min(lenx, leny) let s = makeUninitializedUnsafe(len) @@ -186,8 +182,6 @@ let zipByU = (xs, ys, f) => { s } -let zipBy = (xs, ys, f) => zipByU(xs, ys, (a, b) => f(a, b)) - let concat = (a1, a2) => { let l1 = length(a1) let l2 = length(a2) @@ -325,14 +319,12 @@ let blit = (~src as a1, ~srcOffset as ofs1, ~dst as a2, ~dstOffset as ofs2, ~len } } -let forEachU = (a, f) => +let forEach = (a, f) => for i in 0 to length(a) - 1 { f(getUnsafe(a, i)) } -let forEach = (a, f) => forEachU(a, a => f(a)) - -let mapU = (a, f) => { +let map = (a, f) => { let l = length(a) let r = makeUninitializedUnsafe(l) for i in 0 to l - 1 { @@ -341,13 +333,9 @@ let mapU = (a, f) => { r } -let map = (a, f) => mapU(a, a => f(a)) +let flatMap = (a, f) => concatMany(map(a, f)) -let flatMapU = (a, f) => concatMany(mapU(a, f)) - -let flatMap = (a, f) => flatMapU(a, a => f(a)) - -let getByU = (a, p) => { +let getBy = (a, p) => { let l = length(a) let i = ref(0) let r = ref(None) @@ -361,9 +349,7 @@ let getByU = (a, p) => { r.contents } -let getBy = (a, p) => getByU(a, a => p(a)) - -let getIndexByU = (a, p) => { +let getIndexBy = (a, p) => { let l = length(a) let i = ref(0) let r = ref(None) @@ -377,9 +363,7 @@ let getIndexByU = (a, p) => { r.contents } -let getIndexBy = (a, p) => getIndexByU(a, a => p(a)) - -let keepU = (a, f) => { +let keep = (a, f) => { let l = length(a) let r = makeUninitializedUnsafe(l) let j = ref(0) @@ -394,9 +378,7 @@ let keepU = (a, f) => { r } -let keep = (a, f) => keepU(a, a => f(a)) - -let keepWithIndexU = (a, f) => { +let keepWithIndex = (a, f) => { let l = length(a) let r = makeUninitializedUnsafe(l) let j = ref(0) @@ -411,9 +393,7 @@ let keepWithIndexU = (a, f) => { r } -let keepWithIndex = (a, f) => keepWithIndexU(a, (a, i) => f(a, i)) - -let keepMapU = (a, f) => { +let keepMap = (a, f) => { let l = length(a) let r = makeUninitializedUnsafe(l) let j = ref(0) @@ -430,16 +410,12 @@ let keepMapU = (a, f) => { r } -let keepMap = (a, f) => keepMapU(a, a => f(a)) - -let forEachWithIndexU = (a, f) => +let forEachWithIndex = (a, f) => for i in 0 to length(a) - 1 { f(i, getUnsafe(a, i)) } -let forEachWithIndex = (a, f) => forEachWithIndexU(a, (a, b) => f(a, b)) - -let mapWithIndexU = (a, f) => { +let mapWithIndex = (a, f) => { let l = length(a) let r = makeUninitializedUnsafe(l) for i in 0 to l - 1 { @@ -448,9 +424,7 @@ let mapWithIndexU = (a, f) => { r } -let mapWithIndex = (a, f) => mapWithIndexU(a, (a, b) => f(a, b)) - -let reduceU = (a, x, f) => { +let reduce = (a, x, f) => { let r = ref(x) for i in 0 to length(a) - 1 { r.contents = f(r.contents, getUnsafe(a, i)) @@ -458,9 +432,7 @@ let reduceU = (a, x, f) => { r.contents } -let reduce = (a, x, f) => reduceU(a, x, (a, b) => f(a, b)) - -let reduceReverseU = (a, x, f) => { +let reduceReverse = (a, x, f) => { let r = ref(x) for i in length(a) - 1 downto 0 { r.contents = f(r.contents, getUnsafe(a, i)) @@ -468,9 +440,7 @@ let reduceReverseU = (a, x, f) => { r.contents } -let reduceReverse = (a, x, f) => reduceReverseU(a, x, (a, b) => f(a, b)) - -let reduceReverse2U = (a, b, x, f) => { +let reduceReverse2 = (a, b, x, f) => { let r = ref(x) let len = Pervasives.min(length(a), length(b)) for i in len - 1 downto 0 { @@ -479,9 +449,7 @@ let reduceReverse2U = (a, b, x, f) => { r.contents } -let reduceReverse2 = (a, b, x, f) => reduceReverse2U(a, b, x, (a, b, c) => f(a, b, c)) - -let reduceWithIndexU = (a, x, f) => { +let reduceWithIndex = (a, x, f) => { let r = ref(x) for i in 0 to length(a) - 1 { r.contents = f(r.contents, getUnsafe(a, i), i) @@ -489,8 +457,6 @@ let reduceWithIndexU = (a, x, f) => { r.contents } -let reduceWithIndex = (a, x, f) => reduceWithIndexU(a, x, (a, b, c) => f(a, b, c)) - let rec everyAux = (arr, i, b, len) => if i == len { true @@ -509,20 +475,16 @@ let rec someAux = (arr, i, b, len) => someAux(arr, i + 1, b, len) } -let everyU = (arr, b) => { +let every = (arr, b) => { let len = length(arr) everyAux(arr, 0, b, len) } -let every = (arr, f) => everyU(arr, b => f(b)) - -let someU = (arr, b) => { +let some = (arr, b) => { let len = length(arr) someAux(arr, 0, b, len) } -let some = (arr, f) => someU(arr, b => f(b)) - let rec everyAux2 = (arr1, arr2, i, b, len) => if i == len { true @@ -541,15 +503,11 @@ let rec someAux2 = (arr1, arr2, i, b, len) => someAux2(arr1, arr2, i + 1, b, len) } -let every2U = (a, b, p) => everyAux2(a, b, 0, p, Pervasives.min(length(a), length(b))) +let every2 = (a, b, p) => everyAux2(a, b, 0, p, Pervasives.min(length(a), length(b))) -let every2 = (a, b, p) => every2U(a, b, (a, b) => p(a, b)) +let some2 = (a, b, p) => someAux2(a, b, 0, p, Pervasives.min(length(a), length(b))) -let some2U = (a, b, p) => someAux2(a, b, 0, p, Pervasives.min(length(a), length(b))) - -let some2 = (a, b, p) => some2U(a, b, (a, b) => p(a, b)) - -let eqU = (a, b, p) => { +let eq = (a, b, p) => { let lena = length(a) let lenb = length(b) if lena == lenb { @@ -559,8 +517,6 @@ let eqU = (a, b, p) => { } } -let eq = (a, b, p) => eqU(a, b, (a, b) => p(a, b)) - let rec everyCmpAux2 = (arr1, arr2, i, b, len) => if i == len { 0 @@ -573,7 +529,7 @@ let rec everyCmpAux2 = (arr1, arr2, i, b, len) => } } -let cmpU = (a, b, p) => { +let cmp = (a, b, p) => { let lena = length(a) let lenb = length(b) if lena > lenb { @@ -585,9 +541,7 @@ let cmpU = (a, b, p) => { } } -let cmp = (a, b, p) => cmpU(a, b, (a, b) => p(a, b)) - -let partitionU = (a, f) => { +let partition = (a, f) => { let l = length(a) let i = ref(0) let j = ref(0) @@ -608,8 +562,6 @@ let partitionU = (a, f) => { (a1, a2) } -let partition = (a, f) => partitionU(a, x => f(x)) - let unzip = a => { let l = length(a) let a1 = makeUninitializedUnsafe(l) @@ -622,7 +574,7 @@ let unzip = a => { (a1, a2) } -let joinWithU = (a, sep, toString) => +let joinWith = (a, sep, toString) => switch length(a) { | 0 => "" | l => @@ -637,9 +589,7 @@ let joinWithU = (a, sep, toString) => aux(0, "") } -let joinWith = (a, sep, toString) => joinWithU(a, sep, x => toString(x)) - -let initU = (n, f) => { +let init = (n, f) => { let v = makeUninitializedUnsafe(n) for i in 0 to n - 1 { setUnsafe(v, i, f(i)) @@ -647,6 +597,31 @@ let initU = (n, f) => { v } -let init = (n, f) => initU(n, i => f(i)) +let cmpU = cmp +let eqU = eq +let every2U = every2 +let everyU = every +let flatMapU = flatMap +let forEachU = forEach +let forEachWithIndexU = forEachWithIndex +let getByU = getBy +let getIndexByU = getIndexBy +let initU = init +let joinWithU = joinWith +let keepMapU = keepMap +let keepU = keep +let keepWithIndexU = keepWithIndex +let makeByAndShuffleU = makeByAndShuffle +let makeByU = makeBy +let mapU = map +let mapWithIndexU = mapWithIndex +let partitionU = partition +let reduceReverse2U = reduceReverse2 +let reduceReverseU = reduceReverse +let reduceU = reduce +let reduceWithIndexU = reduceWithIndex +let some2U = some2 +let someU = some +let zipByU = zipBy @send external push: (t<'a>, 'a) => unit = "push" diff --git a/belt/src/belt_Array.resi b/belt/src/belt_Array.resi index ba2c628..4443dd1 100644 --- a/belt/src/belt_Array.resi +++ b/belt/src/belt_Array.resi @@ -205,6 +205,7 @@ Belt.Array.rangeBy(3, 3, ~step=1) == [3] */ let rangeBy: (int, int, ~step: int) => array +@deprecated("Use `makeBy` instead") let makeByU: (int, int => 'a) => t<'a> /** `makeBy(n, f)` return an empty array when n is negative return an array of size @@ -220,6 +221,7 @@ Belt.Array.makeBy(5, (i) => i * i) == [0, 1, 4, 9, 16] */ let makeBy: (int, int => 'a) => t<'a> +@deprecated("Use `makeByAndShuffle` instead") let makeByAndShuffleU: (int, int => 'a) => t<'a> /** Equivalent to `shuffle(makeBy(n, f))` @@ -238,6 +240,7 @@ Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] */ let zip: (t<'a>, array<'b>) => array<('a, 'b)> +@deprecated("Use `zipBy` instead") let zipByU: (t<'a>, array<'b>, ('a, 'b) => 'c) => array<'c> /** `zipBy(xs, ys, f)` create an array by applying `f` to corresponding elements of @@ -392,6 +395,7 @@ Unsafe blit without bounds checking. */ let blitUnsafe: (~src: t<'a>, ~srcOffset: int, ~dst: t<'a>, ~dstOffset: int, ~len: int) => unit +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, 'a => unit) => unit /** `forEach(xs, f)` @@ -420,6 +424,7 @@ total.contents == 1 + 2 + 3 + 4 */ let forEach: (t<'a>, 'a => unit) => unit +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => array<'b> /** `map(xs, f)` returns a new array by calling `f` for each element of `xs` from @@ -433,6 +438,7 @@ Belt.Array.map([1, 2], (x) => x + 1) == [3, 4] */ let map: (t<'a>, 'a => 'b) => array<'b> +@deprecated("Use `flatMap` instead") let flatMapU: (t<'a>, 'a => array<'b>) => array<'b> /** `flatMap(xs, f)` returns a new array by calling `f` for each element of `xs` from @@ -446,6 +452,7 @@ Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] */ let flatMap: (t<'a>, 'a => array<'b>) => array<'b> +@deprecated("Use `getBy` instead") let getByU: (t<'a>, 'a => bool) => option<'a> /** `getBy(xs, p)` returns `Some(value)` for the first value in `xs` that satisifies @@ -460,6 +467,7 @@ Belt.Array.getBy([15, 13, 11], (x) => mod(x, 2) == 0) == None */ let getBy: (t<'a>, 'a => bool) => option<'a> +@deprecated("Use `getIndexBy` instead") let getIndexByU: (t<'a>, 'a => bool) => option /** `getIndexBy(xs, p)` returns `Some(index)` for the first value in `xs` that @@ -475,12 +483,14 @@ Belt.Array.getIndexBy([15, 13, 11], (x) => mod(x, 2) == 0) == None */ let getIndexBy: (t<'a>, 'a => bool) => option +@deprecated("Use `keep` instead") let keepU: (t<'a>, 'a => bool) => t<'a> /** `keep(xs, p)` returns a new array that keep all elements satisfy `p`. */ let keep: (t<'a>, 'a => bool) => t<'a> +@deprecated("Use `keepWithIndex` instead") let keepWithIndexU: (t<'a>, ('a, int) => bool) => t<'a> /** `keepWithIndex(xs, p)` returns a new array that keep all elements satisfy `p`. @@ -493,6 +503,7 @@ Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] */ let keepWithIndex: (t<'a>, ('a, int) => bool) => t<'a> +@deprecated("Use `keepMap` instead") let keepMapU: (t<'a>, 'a => option<'b>) => array<'b> /** `keepMap(xs, p)` returns a new array that keep all elements that return a non @@ -513,6 +524,7 @@ Belt.Array.keepMap([1, 2, 3], x => */ let keepMap: (t<'a>, 'a => option<'b>) => array<'b> +@deprecated("Use `forEachWithIndex` instead") let forEachWithIndexU: (t<'a>, (int, 'a) => unit) => unit /** `forEachWithIndex(xs, f)` same as `Belt.Array.forEach`, except that `f` is @@ -538,6 +550,7 @@ total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 */ let forEachWithIndex: (t<'a>, (int, 'a) => unit) => unit +@deprecated("Use `mapWithIndex` instead") let mapWithIndexU: (t<'a>, (int, 'a) => 'b) => array<'b> /** `mapWithIndex(xs, f)` applies `f` to each element of `xs`. Function `f` takes @@ -551,6 +564,7 @@ Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] */ let mapWithIndex: (t<'a>, (int, 'a) => 'b) => array<'b> +@deprecated("Use `partition` instead") let partitionU: (t<'a>, 'a => bool) => (t<'a>, t<'a>) /** `partition(f, a)` split array into tuple of two arrays based on predicate `f`; @@ -566,6 +580,7 @@ Belt.Array.partition([1, 2, 3, 4, 5], (x) => mod(x, 2) != 0) == ([1, 3, 5], [2, */ let partition: (t<'a>, 'a => bool) => (t<'a>, t<'a>) +@deprecated("Use `reduce` instead") let reduceU: (array<'b>, 'a, ('a, 'b) => 'a) => 'a /** `reduce(xs, init, f)` applies `f` to each element of `xs` from beginning to end. @@ -583,6 +598,7 @@ Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" */ let reduce: (array<'b>, 'a, ('a, 'b) => 'a) => 'a +@deprecated("Use `reduceReverse` instead") let reduceReverseU: (array<'b>, 'a, ('a, 'b) => 'a) => 'a /** `reduceReverse(xs, init, f)` works like `Belt.Array.reduce` except that @@ -596,6 +612,7 @@ Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" */ let reduceReverse: (array<'b>, 'a, ('a, 'b) => 'a) => 'a +@deprecated("Use `reduceReverse2` instead") let reduceReverse2U: (t<'a>, array<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c /** `reduceReverse2(xs, ys, init, f)` reduces two arrays xs and ys;taking items @@ -609,6 +626,7 @@ Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 */ let reduceReverse2: (t<'a>, array<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c +@deprecated("Use `reduceWithIndex` instead") let reduceWithIndexU: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b /** Applies `f` to each element of `xs` from beginning to end. Function `f` has @@ -624,6 +642,7 @@ Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 */ let reduceWithIndex: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b +@deprecated("Use `joinWith` instead") let joinWithU: (t<'a>, string, 'a => string) => string /** `joinWith(xs, sep, toString)` @@ -643,6 +662,7 @@ Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" */ let joinWith: (t<'a>, string, 'a => string) => string +@deprecated("Use `some` instead") let someU: (t<'a>, 'a => bool) => bool /** `some(xs, p)` returns true if at least one of the elements in `xs` satifies `p`; @@ -658,6 +678,7 @@ Belt.Array.some([(-1), (-3), (-5)], (x) => x > 0) == false */ let some: (t<'a>, 'a => bool) => bool +@deprecated("Use `every` instead") let everyU: (t<'a>, 'a => bool) => bool /** `every(xs, p)` returns `true` if all elements satisfy `p`; where `p` is a @@ -673,6 +694,7 @@ Belt.Array.every([1, (-3), 5], (x) => x > 0) == false */ let every: (t<'a>, 'a => bool) => bool +@deprecated("Use `every2` instead") let every2U: (t<'a>, array<'b>, ('a, 'b) => bool) => bool /** `every2(xs, ys, p)` returns true if `p(xi, yi)` is true for all pairs of @@ -692,6 +714,7 @@ Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false */ let every2: (t<'a>, array<'b>, ('a, 'b) => bool) => bool +@deprecated("Use `some2` instead") let some2U: (t<'a>, array<'b>, ('a, 'b) => bool) => bool /** `some2(xs, ys, p)` returns true if `p(xi, yi)` is true for any pair of elements @@ -709,6 +732,7 @@ Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true */ let some2: (t<'a>, array<'b>, ('a, 'b) => bool) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'a>, t<'a>, ('a, 'a) => int) => int /** `cmp(xs, ys, f)` compared by length if `length(xs) != length(ys)`; returning `-1` @@ -730,6 +754,7 @@ Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 */ let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** `eq(xs, ys)` return `false` if length is not the same otherwise compare items @@ -761,6 +786,7 @@ arr == ["ant", "bee", "cat"] */ external truncateToLengthUnsafe: (t<'a>, int) => unit = "length" +@deprecated("Use `init` instead") let initU: (int, int => 'a) => t<'a> let init: (int, int => 'a) => t<'a> diff --git a/belt/src/belt_HashMap.js b/belt/src/belt_HashMap.js index ab08d1f..78df0a4 100644 --- a/belt/src/belt_HashMap.js +++ b/belt/src/belt_HashMap.js @@ -229,15 +229,15 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalBuckets.copy; -let forEachU = Belt_internalBuckets.forEachU; +let forEachU = Belt_internalBuckets.forEach; let forEach = Belt_internalBuckets.forEach; -let reduceU = Belt_internalBuckets.reduceU; +let reduceU = Belt_internalBuckets.reduce; let reduce = Belt_internalBuckets.reduce; -let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlaceU; +let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlace; let keepMapInPlace = Belt_internalBuckets.keepMapInPlace; diff --git a/belt/src/belt_HashMap.res b/belt/src/belt_HashMap.res index 7b0928b..bb85ab3 100644 --- a/belt/src/belt_HashMap.res +++ b/belt/src/belt_HashMap.res @@ -24,11 +24,8 @@ type t<'a, 'b, 'id> = N.t, eq<'a, 'id>, 'a, 'b> let clear = C.clear let size = h => h.C.size let forEach = N.forEach -let forEachU = N.forEachU let reduce = N.reduce -let reduceU = N.reduceU let logStats = N.logStats -let keepMapInPlaceU = N.keepMapInPlaceU let keepMapInPlace = N.keepMapInPlace let toArray = N.toArray let copy = N.copy @@ -227,3 +224,7 @@ let mergeMany = (h, arr) => { module Int = Belt_HashMapInt module String = Belt_HashMapString + +let forEachU = forEach +let reduceU = reduce +let keepMapInPlaceU = keepMapInPlace diff --git a/belt/src/belt_HashMap.resi b/belt/src/belt_HashMap.resi index a391c09..c93a4f8 100644 --- a/belt/src/belt_HashMap.resi +++ b/belt/src/belt_HashMap.resi @@ -242,6 +242,7 @@ Belt.HashMap.has(s0, 1) == false let remove: (t<'key, 'value, 'id>, 'key) => unit /** Same as [forEach](#forEach) but takes uncurried function. */ +@deprecated("Use `forEach` instead") let forEachU: (t<'key, 'value, 'id>, ('key, 'value) => unit) => unit /** @@ -264,6 +265,7 @@ Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) */ let forEach: (t<'key, 'value, 'id>, ('key, 'value) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'key, 'value, 'id>, 'c, ('c, 'key, 'value) => 'c) => 'c /** `reduce(tbl, init, f)` computes `(f(kN, dN) ... (f(k1, d1, init))...)`, where `k1 ... kN` are the keys of all bindings in `tbl`, and `d1 ... dN` are the associated values. Each binding is presented exactly once to `f`. @@ -289,6 +291,7 @@ Belt.HashMap.reduce(s0, "", (acc, key, value) => acc ++ (", " ++ value)) == "val let reduce: (t<'key, 'value, 'id>, 'c, ('c, 'key, 'value) => 'c) => 'c /** Same as [keepMapInPlace](#keepMapInPlace) but takes uncurried function. */ +@deprecated("Use `keepMapInPlace` instead") let keepMapInPlaceU: (t<'key, 'value, 'id>, ('key, 'value) => option<'value>) => unit /** diff --git a/belt/src/belt_HashMapInt.js b/belt/src/belt_HashMapInt.js index 866e4ca..36090d5 100644 --- a/belt/src/belt_HashMapInt.js +++ b/belt/src/belt_HashMapInt.js @@ -215,15 +215,15 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalBuckets.copy; -let forEachU = Belt_internalBuckets.forEachU; +let forEachU = Belt_internalBuckets.forEach; let forEach = Belt_internalBuckets.forEach; -let reduceU = Belt_internalBuckets.reduceU; +let reduceU = Belt_internalBuckets.reduce; let reduce = Belt_internalBuckets.reduce; -let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlaceU; +let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlace; let keepMapInPlace = Belt_internalBuckets.keepMapInPlace; diff --git a/belt/src/belt_HashMapInt.res b/belt/src/belt_HashMapInt.res index 0c19f8c..e567b01 100644 --- a/belt/src/belt_HashMapInt.res +++ b/belt/src/belt_HashMapInt.res @@ -181,12 +181,9 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats -let keepMapInPlaceU = N.keepMapInPlaceU let keepMapInPlace = N.keepMapInPlace let toArray = N.toArray let copy = N.copy @@ -213,3 +210,7 @@ let mergeMany = (h, arr) => { set(h, k, v) } } + +let forEachU = forEach +let reduceU = reduce +let keepMapInPlaceU = keepMapInPlace diff --git a/belt/src/belt_HashMapInt.resi b/belt/src/belt_HashMapInt.resi index b5a5f04..79a4700 100644 --- a/belt/src/belt_HashMapInt.resi +++ b/belt/src/belt_HashMapInt.resi @@ -21,12 +21,15 @@ let has: (t<'b>, key) => bool let remove: (t<'a>, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t<'b>, (key, 'b) => unit) => unit let forEach: (t<'b>, (key, 'b) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c let reduce: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c +@deprecated("Use `keepMapInPlace` instead") let keepMapInPlaceU: (t<'a>, (key, 'a) => option<'a>) => unit let keepMapInPlace: (t<'a>, (key, 'a) => option<'a>) => unit diff --git a/belt/src/belt_HashMapString.js b/belt/src/belt_HashMapString.js index bea77bc..c378c2f 100644 --- a/belt/src/belt_HashMapString.js +++ b/belt/src/belt_HashMapString.js @@ -215,15 +215,15 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalBuckets.copy; -let forEachU = Belt_internalBuckets.forEachU; +let forEachU = Belt_internalBuckets.forEach; let forEach = Belt_internalBuckets.forEach; -let reduceU = Belt_internalBuckets.reduceU; +let reduceU = Belt_internalBuckets.reduce; let reduce = Belt_internalBuckets.reduce; -let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlaceU; +let keepMapInPlaceU = Belt_internalBuckets.keepMapInPlace; let keepMapInPlace = Belt_internalBuckets.keepMapInPlace; diff --git a/belt/src/belt_HashMapString.res b/belt/src/belt_HashMapString.res index c4959dd..ad7d223 100644 --- a/belt/src/belt_HashMapString.res +++ b/belt/src/belt_HashMapString.res @@ -181,12 +181,9 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats -let keepMapInPlaceU = N.keepMapInPlaceU let keepMapInPlace = N.keepMapInPlace let toArray = N.toArray let copy = N.copy @@ -213,3 +210,7 @@ let mergeMany = (h, arr) => { set(h, k, v) } } + +let forEachU = forEach +let reduceU = reduce +let keepMapInPlaceU = keepMapInPlace diff --git a/belt/src/belt_HashMapString.resi b/belt/src/belt_HashMapString.resi index 81a7f51..a45b372 100644 --- a/belt/src/belt_HashMapString.resi +++ b/belt/src/belt_HashMapString.resi @@ -21,12 +21,15 @@ let has: (t<'b>, key) => bool let remove: (t<'a>, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t<'b>, (key, 'b) => unit) => unit let forEach: (t<'b>, (key, 'b) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c let reduce: (t<'b>, 'c, ('c, key, 'b) => 'c) => 'c +@deprecated("Use `keepMapInPlace` instead") let keepMapInPlaceU: (t<'a>, (key, 'a) => option<'a>) => unit let keepMapInPlace: (t<'a>, (key, 'a) => option<'a>) => unit diff --git a/belt/src/belt_HashSet.js b/belt/src/belt_HashSet.js index 78a9a88..9fe3fb0 100644 --- a/belt/src/belt_HashSet.js +++ b/belt/src/belt_HashSet.js @@ -184,11 +184,11 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalSetBuckets.copy; -let forEachU = Belt_internalSetBuckets.forEachU; +let forEachU = Belt_internalSetBuckets.forEach; let forEach = Belt_internalSetBuckets.forEach; -let reduceU = Belt_internalSetBuckets.reduceU; +let reduceU = Belt_internalSetBuckets.reduce; let reduce = Belt_internalSetBuckets.reduce; diff --git a/belt/src/belt_HashSet.res b/belt/src/belt_HashSet.res index 4d2a858..729ca2c 100644 --- a/belt/src/belt_HashSet.res +++ b/belt/src/belt_HashSet.res @@ -158,9 +158,7 @@ let make = (type value identity, ~hintSize, ~id: id) => { let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats let toArray = N.toArray @@ -186,3 +184,6 @@ let mergeMany = (h, arr) => { add0(h, ~eq, ~hash, A.getUnsafe(arr, i)) } } + +let forEachU = forEach +let reduceU = reduce diff --git a/belt/src/belt_HashSet.resi b/belt/src/belt_HashSet.resi index 0fd011c..09a960e 100644 --- a/belt/src/belt_HashSet.resi +++ b/belt/src/belt_HashSet.resi @@ -101,10 +101,12 @@ let has: (t<'a, 'id>, 'a) => bool let remove: (t<'a, 'id>, 'a) => unit +@deprecated("Use `forEach` instead") let forEachU: (t<'a, 'id>, 'a => unit) => unit /** Order unspecified. */ let forEach: (t<'a, 'id>, 'a => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'c /** Order unspecified. */ let reduce: (t<'a, 'id>, 'c, ('c, 'a) => 'c) => 'c diff --git a/belt/src/belt_HashSetInt.js b/belt/src/belt_HashSetInt.js index 9cdfe1e..17ee2a9 100644 --- a/belt/src/belt_HashSetInt.js +++ b/belt/src/belt_HashSetInt.js @@ -171,11 +171,11 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalSetBuckets.copy; -let forEachU = Belt_internalSetBuckets.forEachU; +let forEachU = Belt_internalSetBuckets.forEach; let forEach = Belt_internalSetBuckets.forEach; -let reduceU = Belt_internalSetBuckets.reduceU; +let reduceU = Belt_internalSetBuckets.reduce; let reduce = Belt_internalSetBuckets.reduce; diff --git a/belt/src/belt_HashSetInt.res b/belt/src/belt_HashSetInt.res index f8ad65c..fd159d0 100644 --- a/belt/src/belt_HashSetInt.res +++ b/belt/src/belt_HashSetInt.res @@ -126,9 +126,7 @@ let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats let toArray = N.toArray @@ -152,3 +150,6 @@ let mergeMany = (h, arr) => { add(h, A.getUnsafe(arr, i)) } } + +let forEachU = forEach +let reduceU = reduce diff --git a/belt/src/belt_HashSetInt.resi b/belt/src/belt_HashSetInt.resi index 526ffc2..edf26dd 100644 --- a/belt/src/belt_HashSetInt.resi +++ b/belt/src/belt_HashSetInt.resi @@ -49,9 +49,11 @@ let has: (t, key) => bool let remove: (t, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t, key => unit) => unit let forEach: (t, key => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'c, ('c, key) => 'c) => 'c let reduce: (t, 'c, ('c, key) => 'c) => 'c diff --git a/belt/src/belt_HashSetString.js b/belt/src/belt_HashSetString.js index a214048..48d111a 100644 --- a/belt/src/belt_HashSetString.js +++ b/belt/src/belt_HashSetString.js @@ -171,11 +171,11 @@ let isEmpty = Belt_internalBucketsType.isEmpty; let copy = Belt_internalSetBuckets.copy; -let forEachU = Belt_internalSetBuckets.forEachU; +let forEachU = Belt_internalSetBuckets.forEach; let forEach = Belt_internalSetBuckets.forEach; -let reduceU = Belt_internalSetBuckets.reduceU; +let reduceU = Belt_internalSetBuckets.reduce; let reduce = Belt_internalSetBuckets.reduce; diff --git a/belt/src/belt_HashSetString.res b/belt/src/belt_HashSetString.res index be19839..9ce5273 100644 --- a/belt/src/belt_HashSetString.res +++ b/belt/src/belt_HashSetString.res @@ -126,9 +126,7 @@ let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear let size = h => h.C.size -let forEachU = N.forEachU let forEach = N.forEach -let reduceU = N.reduceU let reduce = N.reduce let logStats = N.logStats let toArray = N.toArray @@ -152,3 +150,6 @@ let mergeMany = (h, arr) => { add(h, A.getUnsafe(arr, i)) } } + +let forEachU = forEach +let reduceU = reduce diff --git a/belt/src/belt_HashSetString.resi b/belt/src/belt_HashSetString.resi index f4dbad1..3e3212b 100644 --- a/belt/src/belt_HashSetString.resi +++ b/belt/src/belt_HashSetString.resi @@ -49,9 +49,11 @@ let has: (t, key) => bool let remove: (t, key) => unit +@deprecated("Use `forEach` instead") let forEachU: (t, key => unit) => unit let forEach: (t, key => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'c, ('c, key) => 'c) => 'c let reduce: (t, 'c, ('c, key) => 'c) => 'c diff --git a/belt/src/belt_Id.js b/belt/src/belt_Id.js index 562e578..2b6ffd1 100644 --- a/belt/src/belt_Id.js +++ b/belt/src/belt_Id.js @@ -1,73 +1,34 @@ -function MakeComparableU(M) { - return M; -} - function MakeComparable(M) { - let cmp = M.cmp; - let cmp$1 = function (a, b) { - return cmp(a, b); - }; - return { - cmp: cmp$1 - }; -} - -function comparableU(cmp) { - return { - cmp: cmp - }; + return M; } function comparable(cmp) { - let cmp$1 = function (a, b) { - return cmp(a, b); - }; return { - cmp: cmp$1 + cmp: cmp }; } -function MakeHashableU(M) { - return M; -} - function MakeHashable(M) { - let hash = M.hash; - let hash$1 = function (a) { - return hash(a); - }; - let eq = M.eq; - let eq$1 = function (a, b) { - return eq(a, b); - }; - return { - hash: hash$1, - eq: eq$1 - }; + return M; } -function hashableU(hash, eq) { +function hashable(hash, eq) { return { hash: hash, eq: eq }; } -function hashable(hash, eq) { - let hash$1 = function (a) { - return hash(a); - }; - let eq$1 = function (a, b) { - return eq(a, b); - }; - return { - hash: hash$1, - eq: eq$1 - }; -} +let MakeComparableU = MakeComparable; + +let comparableU = comparable; + +let MakeHashableU = MakeHashable; + +let hashableU = hashable; export { MakeComparableU, diff --git a/belt/src/belt_Id.res b/belt/src/belt_Id.res index d88456e..01f2a84 100644 --- a/belt/src/belt_Id.res +++ b/belt/src/belt_Id.res @@ -38,16 +38,6 @@ module type Comparable = { type comparable<'key, 'id> = module(Comparable with type t = 'key and type identity = 'id) -module MakeComparableU = ( - M: { - type t - let cmp: (t, t) => int - }, -) => { - type identity - include M -} - module MakeComparable = ( M: { type t @@ -55,30 +45,17 @@ module MakeComparable = ( }, ) => { type identity - type t = M.t - /* see https://github.com/rescript-lang/rescript-compiler/pull/2589/files/5ef875b7665ee08cfdc59af368fc52bac1fe9130#r173330825 */ - let cmp = { - let cmp = M.cmp - (a, b) => cmp(a, b) - } + include M } -let comparableU = (type key, ~cmp): module(Comparable with type t = key) => +let comparable = (type key, ~cmp): module(Comparable with type t = key) => module( - MakeComparableU({ + MakeComparable({ type t = key let cmp = cmp }) ) -let comparable = (type key, ~cmp) => { - module N = MakeComparable({ - type t = key - let cmp = cmp - }) - module(N: Comparable with type t = key) -} - module type Hashable = { type identity type t @@ -88,17 +65,6 @@ module type Hashable = { type hashable<'key, 'id> = module(Hashable with type t = 'key and type identity = 'id) -module MakeHashableU = ( - M: { - type t - let hash: t => int - let eq: (t, t) => bool - }, -) => { - type identity - include M -} - module MakeHashable = ( M: { type t @@ -107,31 +73,20 @@ module MakeHashable = ( }, ) => { type identity - type t = M.t - let hash = { - let hash = M.hash - a => hash(a) - } - let eq = { - let eq = M.eq - (a, b) => eq(a, b) - } + include M } -let hashableU = (type key, ~hash, ~eq): module(Hashable with type t = key) => +let hashable = (type key, ~hash, ~eq): module(Hashable with type t = key) => module( - MakeHashableU({ + MakeHashable({ type t = key let hash = hash let eq = eq }) ) -let hashable = (type key, ~hash, ~eq) => { - module N = MakeHashable({ - type t = key - let hash = hash - let eq = eq - }) - module(N: Hashable with type t = key) -} +module MakeComparableU = MakeComparable +module MakeHashableU = MakeHashable + +let comparableU = comparable +let hashableU = hashable diff --git a/belt/src/belt_Id.resi b/belt/src/belt_Id.resi index 921d783..ca23d17 100644 --- a/belt/src/belt_Id.resi +++ b/belt/src/belt_Id.resi @@ -75,6 +75,7 @@ mismatch if they use different comparison function */ type comparable<'key, 'id> = module(Comparable with type t = 'key and type identity = 'id) +@deprecated("Use `MakeComparable` instead") module MakeComparableU: ( M: { type t @@ -89,6 +90,7 @@ module MakeComparable: ( }, ) => (Comparable with type t = M.t) +@deprecated("Use `comparable` instead") let comparableU: (~cmp: ('a, 'a) => int) => module(Comparable with type t = 'a) /** @@ -124,6 +126,7 @@ mismatch if they use different comparison function */ type hashable<'key, 'id> = module(Hashable with type t = 'key and type identity = 'id) +@deprecated("Use `MakeHashable` instead") module MakeHashableU: ( M: { type t @@ -140,6 +143,7 @@ module MakeHashable: ( }, ) => (Hashable with type t = M.t) +@deprecated("Use `hashable` instead") let hashableU: (~hash: 'a => int, ~eq: ('a, 'a) => bool) => module(Hashable with type t = 'a) let hashable: (~hash: 'a => int, ~eq: ('a, 'a) => bool) => module(Hashable with type t = 'a) diff --git a/belt/src/belt_List.js b/belt/src/belt_List.js index f6fa499..3cb0fbd 100644 --- a/belt/src/belt_List.js +++ b/belt/src/belt_List.js @@ -513,7 +513,7 @@ function concat(xs, ys) { return cell; } -function mapU(xs, f) { +function map(xs, f) { if (!xs) { return /* [] */0; } @@ -525,13 +525,7 @@ function mapU(xs, f) { return cell; } -function map(xs, f) { - return mapU(xs, (function (x) { - return f(x); - })); -} - -function zipByU(l1, l2, f) { +function zipBy(l1, l2, f) { if (!l1) { return /* [] */0; } @@ -546,13 +540,7 @@ function zipByU(l1, l2, f) { return cell; } -function zipBy(l1, l2, f) { - return zipByU(l1, l2, (function (x, y) { - return f(x, y); - })); -} - -function mapWithIndexU(xs, f) { +function mapWithIndex(xs, f) { if (!xs) { return /* [] */0; } @@ -564,13 +552,7 @@ function mapWithIndexU(xs, f) { return cell; } -function mapWithIndex(xs, f) { - return mapWithIndexU(xs, (function (i, x) { - return f(i, x); - })); -} - -function makeByU(n, f) { +function makeBy(n, f) { if (n <= 0) { return /* [] */0; } @@ -592,12 +574,6 @@ function makeByU(n, f) { return headX; } -function makeBy(n, f) { - return makeByU(n, (function (x) { - return f(x); - })); -} - function make(n, v) { if (n <= 0) { return /* [] */0; @@ -750,7 +726,7 @@ function concatMany(xs) { return v; } -function mapReverseU(l, f) { +function mapReverse(l, f) { let _accu = /* [] */0; let _xs = l; while(true) { @@ -768,13 +744,7 @@ function mapReverseU(l, f) { }; } -function mapReverse(l, f) { - return mapReverseU(l, (function (x) { - return f(x); - })); -} - -function forEachU(_xs, f) { +function forEach(_xs, f) { while(true) { let xs = _xs; if (!xs) { @@ -786,13 +756,7 @@ function forEachU(_xs, f) { }; } -function forEach(xs, f) { - forEachU(xs, (function (x) { - return f(x); - })); -} - -function forEachWithIndexU(l, f) { +function forEachWithIndex(l, f) { let _xs = l; let _i = 0; while(true) { @@ -808,13 +772,7 @@ function forEachWithIndexU(l, f) { }; } -function forEachWithIndex(l, f) { - forEachWithIndexU(l, (function (i, x) { - return f(i, x); - })); -} - -function reduceU(_l, _accu, f) { +function reduce(_l, _accu, f) { while(true) { let accu = _accu; let l = _l; @@ -827,36 +785,24 @@ function reduceU(_l, _accu, f) { }; } -function reduce(l, accu, f) { - return reduceU(l, accu, (function (acc, x) { - return f(acc, x); - })); -} - -function reduceReverseUnsafeU(l, accu, f) { +function reduceReverseUnsafe(l, accu, f) { if (l) { - return f(reduceReverseUnsafeU(l.tl, accu, f), l.hd); + return f(reduceReverseUnsafe(l.tl, accu, f), l.hd); } else { return accu; } } -function reduceReverseU(l, acc, f) { +function reduceReverse(l, acc, f) { let len = length(l); if (len < 1000) { - return reduceReverseUnsafeU(l, acc, f); + return reduceReverseUnsafe(l, acc, f); } else { - return Belt_Array.reduceReverseU(toArray(l), acc, f); + return Belt_Array.reduceReverse(toArray(l), acc, f); } } -function reduceReverse(l, accu, f) { - return reduceReverseU(l, accu, (function (a, b) { - return f(a, b); - })); -} - -function reduceWithIndexU(l, acc, f) { +function reduceWithIndex(l, acc, f) { let _l = l; let _acc = acc; let _i = 0; @@ -874,13 +820,7 @@ function reduceWithIndexU(l, acc, f) { }; } -function reduceWithIndex(l, acc, f) { - return reduceWithIndexU(l, acc, (function (acc, x, i) { - return f(acc, x, i); - })); -} - -function mapReverse2U(l1, l2, f) { +function mapReverse2(l1, l2, f) { let _l1 = l1; let _l2 = l2; let _accu = /* [] */0; @@ -904,13 +844,7 @@ function mapReverse2U(l1, l2, f) { }; } -function mapReverse2(l1, l2, f) { - return mapReverse2U(l1, l2, (function (a, b) { - return f(a, b); - })); -} - -function forEach2U(_l1, _l2, f) { +function forEach2(_l1, _l2, f) { while(true) { let l2 = _l2; let l1 = _l1; @@ -927,13 +861,7 @@ function forEach2U(_l1, _l2, f) { }; } -function forEach2(l1, l2, f) { - forEach2U(l1, l2, (function (a, b) { - return f(a, b); - })); -} - -function reduce2U(_l1, _l2, _accu, f) { +function reduce2(_l1, _l2, _accu, f) { while(true) { let accu = _accu; let l2 = _l2; @@ -951,36 +879,24 @@ function reduce2U(_l1, _l2, _accu, f) { }; } -function reduce2(l1, l2, acc, f) { - return reduce2U(l1, l2, acc, (function (a, b, c) { - return f(a, b, c); - })); -} - -function reduceReverse2UnsafeU(l1, l2, accu, f) { +function reduceReverse2Unsafe(l1, l2, accu, f) { if (l1 && l2) { - return f(reduceReverse2UnsafeU(l1.tl, l2.tl, accu, f), l1.hd, l2.hd); + return f(reduceReverse2Unsafe(l1.tl, l2.tl, accu, f), l1.hd, l2.hd); } else { return accu; } } -function reduceReverse2U(l1, l2, acc, f) { +function reduceReverse2(l1, l2, acc, f) { let len = length(l1); if (len < 1000) { - return reduceReverse2UnsafeU(l1, l2, acc, f); + return reduceReverse2Unsafe(l1, l2, acc, f); } else { - return Belt_Array.reduceReverse2U(toArray(l1), toArray(l2), acc, f); + return Belt_Array.reduceReverse2(toArray(l1), toArray(l2), acc, f); } } -function reduceReverse2(l1, l2, acc, f) { - return reduceReverse2U(l1, l2, acc, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(_xs, p) { +function every(_xs, p) { while(true) { let xs = _xs; if (!xs) { @@ -994,13 +910,7 @@ function everyU(_xs, p) { }; } -function every(xs, p) { - return everyU(xs, (function (x) { - return p(x); - })); -} - -function someU(_xs, p) { +function some(_xs, p) { while(true) { let xs = _xs; if (!xs) { @@ -1014,13 +924,7 @@ function someU(_xs, p) { }; } -function some(xs, p) { - return someU(xs, (function (x) { - return p(x); - })); -} - -function every2U(_l1, _l2, p) { +function every2(_l1, _l2, p) { while(true) { let l2 = _l2; let l1 = _l1; @@ -1039,12 +943,6 @@ function every2U(_l1, _l2, p) { }; } -function every2(l1, l2, p) { - return every2U(l1, l2, (function (a, b) { - return p(a, b); - })); -} - function cmpByLength(_l1, _l2) { while(true) { let l2 = _l2; @@ -1065,7 +963,7 @@ function cmpByLength(_l1, _l2) { }; } -function cmpU(_l1, _l2, p) { +function cmp(_l1, _l2, p) { while(true) { let l2 = _l2; let l1 = _l1; @@ -1089,13 +987,7 @@ function cmpU(_l1, _l2, p) { }; } -function cmp(l1, l2, f) { - return cmpU(l1, l2, (function (x, y) { - return f(x, y); - })); -} - -function eqU(_l1, _l2, p) { +function eq(_l1, _l2, p) { while(true) { let l2 = _l2; let l1 = _l1; @@ -1118,13 +1010,7 @@ function eqU(_l1, _l2, p) { }; } -function eq(l1, l2, f) { - return eqU(l1, l2, (function (x, y) { - return f(x, y); - })); -} - -function some2U(_l1, _l2, p) { +function some2(_l1, _l2, p) { while(true) { let l2 = _l2; let l1 = _l1; @@ -1143,13 +1029,7 @@ function some2U(_l1, _l2, p) { }; } -function some2(l1, l2, p) { - return some2U(l1, l2, (function (a, b) { - return p(a, b); - })); -} - -function hasU(_xs, x, eq) { +function has(_xs, x, eq) { while(true) { let xs = _xs; if (!xs) { @@ -1163,13 +1043,7 @@ function hasU(_xs, x, eq) { }; } -function has(xs, x, eq) { - return hasU(xs, x, (function (a, b) { - return eq(a, b); - })); -} - -function getAssocU(_xs, x, eq) { +function getAssoc(_xs, x, eq) { while(true) { let xs = _xs; if (!xs) { @@ -1184,13 +1058,7 @@ function getAssocU(_xs, x, eq) { }; } -function getAssoc(xs, x, eq) { - return getAssocU(xs, x, (function (a, b) { - return eq(a, b); - })); -} - -function hasAssocU(_xs, x, eq) { +function hasAssoc(_xs, x, eq) { while(true) { let xs = _xs; if (!xs) { @@ -1204,13 +1072,7 @@ function hasAssocU(_xs, x, eq) { }; } -function hasAssoc(xs, x, eq) { - return hasAssocU(xs, x, (function (a, b) { - return eq(a, b); - })); -} - -function removeAssocU(xs, x, eq) { +function removeAssoc(xs, x, eq) { if (!xs) { return /* [] */0; } @@ -1231,13 +1093,7 @@ function removeAssocU(xs, x, eq) { } } -function removeAssoc(xs, x, eq) { - return removeAssocU(xs, x, (function (a, b) { - return eq(a, b); - })); -} - -function setAssocU(xs, x, k, eq) { +function setAssoc(xs, x, k, eq) { if (!xs) { return { hd: [ @@ -1276,25 +1132,13 @@ function setAssocU(xs, x, k, eq) { } } -function setAssoc(xs, x, k, eq) { - return setAssocU(xs, x, k, (function (a, b) { - return eq(a, b); - })); -} - -function sortU(xs, cmp) { +function sort(xs, cmp) { let arr = toArray(xs); - Belt_SortArray.stableSortInPlaceByU(arr, cmp); + Belt_SortArray.stableSortInPlaceBy(arr, cmp); return fromArray(arr); } -function sort(xs, cmp) { - return sortU(xs, (function (x, y) { - return cmp(x, y); - })); -} - -function getByU(_xs, p) { +function getBy(_xs, p) { while(true) { let xs = _xs; if (!xs) { @@ -1309,13 +1153,7 @@ function getByU(_xs, p) { }; } -function getBy(xs, p) { - return getByU(xs, (function (a) { - return p(a); - })); -} - -function keepU(_xs, p) { +function keep(_xs, p) { while(true) { let xs = _xs; if (!xs) { @@ -1336,13 +1174,7 @@ function keepU(_xs, p) { }; } -function keep(xs, p) { - return keepU(xs, (function (x) { - return p(x); - })); -} - -function keepWithIndexU(xs, p) { +function keepWithIndex(xs, p) { let _xs = xs; let _i = 0; while(true) { @@ -1367,13 +1199,7 @@ function keepWithIndexU(xs, p) { }; } -function keepWithIndex(xs, p) { - return keepWithIndexU(xs, (function (x, i) { - return p(x, i); - })); -} - -function keepMapU(_xs, p) { +function keepMap(_xs, p) { while(true) { let xs = _xs; if (!xs) { @@ -1394,13 +1220,7 @@ function keepMapU(_xs, p) { }; } -function keepMap(xs, p) { - return keepMapU(xs, (function (x) { - return p(x); - })); -} - -function partitionU(l, p) { +function partition(l, p) { if (!l) { return [ /* [] */0, @@ -1431,12 +1251,6 @@ function partitionU(l, p) { } } -function partition(l, p) { - return partitionU(l, (function (x) { - return p(x); - })); -} - function unzip(xs) { if (!xs) { return [ @@ -1480,10 +1294,72 @@ function zip(l1, l2) { let size = length; +let makeByU = makeBy; + +let mapU = map; + +let zipByU = zipBy; + +let mapWithIndexU = mapWithIndex; + +let mapReverseU = mapReverse; + +let forEachU = forEach; + +let forEachWithIndexU = forEachWithIndex; + +let reduceU = reduce; + +let reduceWithIndexU = reduceWithIndex; + +let reduceReverseU = reduceReverse; + +let mapReverse2U = mapReverse2; + +let forEach2U = forEach2; + +let reduce2U = reduce2; + +let reduceReverse2U = reduceReverse2; + +let everyU = every; + +let someU = some; + +let every2U = every2; + +let some2U = some2; + +let cmpU = cmp; + +let eqU = eq; + +let hasU = has; + +let getByU = getBy; + +let keepU = keep; + let filter = keep; +let keepWithIndexU = keepWithIndex; + let filterWithIndex = keepWithIndex; +let keepMapU = keepMap; + +let partitionU = partition; + +let getAssocU = getAssoc; + +let hasAssocU = hasAssoc; + +let removeAssocU = removeAssoc; + +let setAssocU = setAssoc; + +let sortU = sort; + export { length, size, diff --git a/belt/src/belt_List.res b/belt/src/belt_List.res index ff661eb..038d402 100644 --- a/belt/src/belt_List.res +++ b/belt/src/belt_List.res @@ -373,7 +373,7 @@ let concat = (xs, ys) => cell } -let mapU = (xs, f) => +let map = (xs, f) => switch xs { | list{} => list{} | list{h, ...t} => @@ -382,9 +382,7 @@ let mapU = (xs, f) => cell } -let map = (xs, f) => mapU(xs, x => f(x)) - -let zipByU = (l1, l2, f) => +let zipBy = (l1, l2, f) => switch (l1, l2) { | (list{a1, ...l1}, list{a2, ...l2}) => let cell = mutableCell(f(a1, a2), list{}) @@ -393,9 +391,7 @@ let zipByU = (l1, l2, f) => | (list{}, _) | (_, list{}) => list{} } -let zipBy = (l1, l2, f) => zipByU(l1, l2, (x, y) => f(x, y)) - -let mapWithIndexU = (xs, f) => +let mapWithIndex = (xs, f) => switch xs { | list{} => list{} | list{h, ...t} => @@ -404,9 +400,7 @@ let mapWithIndexU = (xs, f) => cell } -let mapWithIndex = (xs, f) => mapWithIndexU(xs, (i, x) => f(i, x)) - -let makeByU = (n, f) => +let makeBy = (n, f) => if n <= 0 { list{} } else { @@ -423,8 +417,6 @@ let makeByU = (n, f) => headX } -let makeBy = (n, f) => makeByU(n, x => f(x)) - let make = (type a, n, v: a): list => if n <= 0 { list{} @@ -544,20 +536,16 @@ let rec mapRevAux = (f, accu, xs) => | list{a, ...l} => mapRevAux(f, list{f(a), ...accu}, l) } -let mapReverseU = (l, f) => mapRevAux(f, list{}, l) +let mapReverse = (l, f) => mapRevAux(f, list{}, l) -let mapReverse = (l, f) => mapReverseU(l, x => f(x)) - -let rec forEachU = (xs, f) => +let rec forEach = (xs, f) => switch xs { | list{} => () | list{a, ...l} => f(a)->ignore - forEachU(l, f) + forEach(l, f) } -let forEach = (xs, f) => forEachU(xs, x => f(x)) - let rec iteri = (xs, i, f) => switch xs { | list{} => () @@ -566,43 +554,36 @@ let rec iteri = (xs, i, f) => iteri(l, i + 1, f) } -let forEachWithIndexU = (l, f) => iteri(l, 0, f) -let forEachWithIndex = (l, f) => forEachWithIndexU(l, (i, x) => f(i, x)) +let forEachWithIndex = (l, f) => iteri(l, 0, f) -let rec reduceU = (l, accu, f) => +let rec reduce = (l, accu, f) => switch l { | list{} => accu - | list{a, ...l} => reduceU(l, f(accu, a), f) + | list{a, ...l} => reduce(l, f(accu, a), f) } -let reduce = (l, accu, f) => reduceU(l, accu, (acc, x) => f(acc, x)) - -let rec reduceReverseUnsafeU = (l, accu, f) => +let rec reduceReverseUnsafe = (l, accu, f) => switch l { | list{} => accu - | list{a, ...l} => f(reduceReverseUnsafeU(l, accu, f), a) + | list{a, ...l} => f(reduceReverseUnsafe(l, accu, f), a) } -let reduceReverseU = (type a b, l: list, acc: b, f) => { +let reduceReverse = (type a b, l: list, acc: b, f) => { let len = length(l) if len < 1000 { - reduceReverseUnsafeU(l, acc, f) + reduceReverseUnsafe(l, acc, f) } else { - A.reduceReverseU(toArray(l), acc, f) + A.reduceReverse(toArray(l), acc, f) } } -let reduceReverse = (l, accu, f) => reduceReverseU(l, accu, (a, b) => f(a, b)) - -let rec reduceWithIndexAuxU = (l, acc, f, i) => +let rec reduceWithIndexAux = (l, acc, f, i) => switch l { | list{} => acc - | list{x, ...xs} => reduceWithIndexAuxU(xs, f(acc, x, i), f, i + 1) + | list{x, ...xs} => reduceWithIndexAux(xs, f(acc, x, i), f, i + 1) } -let reduceWithIndexU = (l, acc, f) => reduceWithIndexAuxU(l, acc, f, 0) - -let reduceWithIndex = (l, acc, f) => reduceWithIndexU(l, acc, (acc, x, i) => f(acc, x, i)) +let reduceWithIndex = (l, acc, f) => reduceWithIndexAux(l, acc, f, 0) let rec mapRevAux2 = (l1, l2, accu, f) => switch (l1, l2) { @@ -610,70 +591,56 @@ let rec mapRevAux2 = (l1, l2, accu, f) => | (_, list{}) | (list{}, _) => accu } -let mapReverse2U = (l1, l2, f) => mapRevAux2(l1, l2, list{}, f) - -let mapReverse2 = (l1, l2, f) => mapReverse2U(l1, l2, (a, b) => f(a, b)) +let mapReverse2 = (l1, l2, f) => mapRevAux2(l1, l2, list{}, f) -let rec forEach2U = (l1, l2, f) => +let rec forEach2 = (l1, l2, f) => switch (l1, l2) { | (list{a1, ...l1}, list{a2, ...l2}) => f(a1, a2)->ignore - forEach2U(l1, l2, f) + forEach2(l1, l2, f) | (list{}, _) | (_, list{}) => () } -let forEach2 = (l1, l2, f) => forEach2U(l1, l2, (a, b) => f(a, b)) - -let rec reduce2U = (l1, l2, accu, f) => +let rec reduce2 = (l1, l2, accu, f) => switch (l1, l2) { - | (list{a1, ...l1}, list{a2, ...l2}) => reduce2U(l1, l2, f(accu, a1, a2), f) + | (list{a1, ...l1}, list{a2, ...l2}) => reduce2(l1, l2, f(accu, a1, a2), f) | (list{}, _) | (_, list{}) => accu } -let reduce2 = (l1, l2, acc, f) => reduce2U(l1, l2, acc, (a, b, c) => f(a, b, c)) - -let rec reduceReverse2UnsafeU = (l1, l2, accu, f) => +let rec reduceReverse2Unsafe = (l1, l2, accu, f) => switch (l1, l2) { | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => f(reduceReverse2UnsafeU(l1, l2, accu, f), a1, a2) + | (list{a1, ...l1}, list{a2, ...l2}) => f(reduceReverse2Unsafe(l1, l2, accu, f), a1, a2) | (_, list{}) | (list{}, _) => accu } -let reduceReverse2U = (type a b c, l1: list, l2: list, acc: c, f) => { +let reduceReverse2 = (type a b c, l1: list, l2: list, acc: c, f) => { let len = length(l1) if len < 1000 { - reduceReverse2UnsafeU(l1, l2, acc, f) + reduceReverse2Unsafe(l1, l2, acc, f) } else { - A.reduceReverse2U(toArray(l1), toArray(l2), acc, f) + A.reduceReverse2(toArray(l1), toArray(l2), acc, f) } } -let reduceReverse2 = (l1, l2, acc, f) => reduceReverse2U(l1, l2, acc, (a, b, c) => f(a, b, c)) - -let rec everyU = (xs, p) => +let rec every = (xs, p) => switch xs { | list{} => true - | list{a, ...l} => p(a) && everyU(l, p) + | list{a, ...l} => p(a) && every(l, p) } -let every = (xs, p) => everyU(xs, x => p(x)) - -let rec someU = (xs, p) => +let rec some = (xs, p) => switch xs { | list{} => false - | list{a, ...l} => p(a) || someU(l, p) + | list{a, ...l} => p(a) || some(l, p) } -let some = (xs, p) => someU(xs, x => p(x)) - -let rec every2U = (l1, l2, p) => +let rec every2 = (l1, l2, p) => switch (l1, l2) { | (_, list{}) | (list{}, _) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && every2U(l1, l2, p) + | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && every2(l1, l2, p) } -let every2 = (l1, l2, p) => every2U(l1, l2, (a, b) => p(a, b)) - let rec cmpByLength = (l1, l2) => switch (l1, l2) { | (list{}, list{}) => 0 @@ -682,7 +649,7 @@ let rec cmpByLength = (l1, l2) => | (list{_, ...l1s}, list{_, ...l2s}) => cmpByLength(l1s, l2s) } -let rec cmpU = (l1, l2, p) => +let rec cmp = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => 0 | (_, list{}) => 1 @@ -690,66 +657,55 @@ let rec cmpU = (l1, l2, p) => | (list{a1, ...l1}, list{a2, ...l2}) => let c = p(a1, a2) if c == 0 { - cmpU(l1, l2, p) + cmp(l1, l2, p) } else { c } } -let cmp = (l1, l2, f) => cmpU(l1, l2, (x, y) => f(x, y)) - -let rec eqU = (l1, l2, p) => +let rec eq = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => true | (_, list{}) | (list{}, _) => false | (list{a1, ...l1}, list{a2, ...l2}) => if p(a1, a2) { - eqU(l1, l2, p) + eq(l1, l2, p) } else { false } } -let eq = (l1, l2, f) => eqU(l1, l2, (x, y) => f(x, y)) -let rec some2U = (l1, l2, p) => +let rec some2 = (l1, l2, p) => switch (l1, l2) { | (list{}, _) | (_, list{}) => false - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || some2U(l1, l2, p) + | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || some2(l1, l2, p) } -let some2 = (l1, l2, p) => some2U(l1, l2, (a, b) => p(a, b)) - -let rec hasU = (xs, x, eq) => +let rec has = (xs, x, eq) => switch xs { | list{} => false - | list{a, ...l} => eq(a, x) || hasU(l, x, eq) + | list{a, ...l} => eq(a, x) || has(l, x, eq) } -let has = (xs, x, eq) => hasU(xs, x, (a, b) => eq(a, b)) - -let rec getAssocU = (xs, x, eq) => +let rec getAssoc = (xs, x, eq) => switch xs { | list{} => None | list{(a, b), ...l} => if eq(a, x) { Some(b) } else { - getAssocU(l, x, eq) + getAssoc(l, x, eq) } } -let getAssoc = (xs, x, eq) => getAssocU(xs, x, (a, b) => eq(a, b)) - -let rec hasAssocU = (xs, x, eq) => +let rec hasAssoc = (xs, x, eq) => switch xs { | list{} => false - | list{(a, _), ...l} => eq(a, x) || hasAssocU(l, x, eq) + | list{(a, _), ...l} => eq(a, x) || hasAssoc(l, x, eq) } -let hasAssoc = (xs, x, eq) => hasAssocU(xs, x, (a, b) => eq(a, b)) - -let removeAssocU = (xs, x, eq) => +let removeAssoc = (xs, x, eq) => switch xs { | list{} => list{} | list{(a, _) as pair, ...l} => @@ -766,9 +722,7 @@ let removeAssocU = (xs, x, eq) => } } -let removeAssoc = (xs, x, eq) => removeAssocU(xs, x, (a, b) => eq(a, b)) - -let setAssocU = (xs, x, k, eq) => +let setAssoc = (xs, x, k, eq) => switch xs { | list{} => list{(x, k)} | list{(a, _) as pair, ...l} => @@ -785,30 +739,24 @@ let setAssocU = (xs, x, k, eq) => } } -let setAssoc = (xs, x, k, eq) => setAssocU(xs, x, k, (a, b) => eq(a, b)) - -let sortU = (xs, cmp) => { +let sort = (xs, cmp) => { let arr = toArray(xs) - Belt_SortArray.stableSortInPlaceByU(arr, cmp) + Belt_SortArray.stableSortInPlaceBy(arr, cmp) fromArray(arr) } -let sort = (xs, cmp) => sortU(xs, (x, y) => cmp(x, y)) - -let rec getByU = (xs, p) => +let rec getBy = (xs, p) => switch xs { | list{} => None | list{x, ...l} => if p(x) { Some(x) } else { - getByU(l, p) + getBy(l, p) } } -let getBy = (xs, p) => getByU(xs, a => p(a)) - -let rec keepU = (xs, p) => +let rec keep = (xs, p) => switch xs { | list{} => list{} | list{h, ...t} => @@ -817,15 +765,13 @@ let rec keepU = (xs, p) => copyAuxWitFilter(p, t, cell) cell } else { - keepU(t, p) + keep(t, p) } } -let keep = (xs, p) => keepU(xs, x => p(x)) - let filter = keep -let keepWithIndexU = (xs, p) => { +let keepWithIndex = (xs, p) => { let rec auxKeepWithIndex = (xs, p, i) => switch xs { | list{} => list{} @@ -841,11 +787,9 @@ let keepWithIndexU = (xs, p) => { auxKeepWithIndex(xs, p, 0) } -let keepWithIndex = (xs, p) => keepWithIndexU(xs, (x, i) => p(x, i)) - let filterWithIndex = keepWithIndex -let rec keepMapU = (xs, p) => +let rec keepMap = (xs, p) => switch xs { | list{} => list{} | list{h, ...t} => @@ -854,13 +798,11 @@ let rec keepMapU = (xs, p) => let cell = mutableCell(h, list{}) copyAuxWitFilterMap(p, t, cell) cell - | None => keepMapU(t, p) + | None => keepMap(t, p) } } -let keepMap = (xs, p) => keepMapU(xs, x => p(x)) - -let partitionU = (l, p) => +let partition = (l, p) => switch l { | list{} => (list{}, list{}) | list{h, ...t} => @@ -887,8 +829,6 @@ let partitionU = (l, p) => } } -let partition = (l, p) => partitionU(l, x => p(x)) - let unzip = xs => switch xs { | list{} => (list{}, list{}) @@ -907,3 +847,35 @@ let zip = (l1, l2) => zipAux(l1, l2, cell) cell } + +let cmpU = cmp +let eqU = eq +let every2U = every2 +let everyU = every +let forEach2U = forEach2 +let forEachU = forEach +let forEachWithIndexU = forEachWithIndex +let getAssocU = getAssoc +let getByU = getBy +let hasAssocU = hasAssoc +let hasU = has +let keepMapU = keepMap +let keepU = keep +let keepWithIndexU = keepWithIndex +let makeByU = makeBy +let mapReverse2U = mapReverse2 +let mapReverseU = mapReverse +let mapU = map +let mapWithIndexU = mapWithIndex +let partitionU = partition +let reduce2U = reduce2 +let reduceReverse2U = reduceReverse2 +let reduceReverseU = reduceReverse +let reduceU = reduce +let reduceWithIndexU = reduceWithIndex +let removeAssocU = removeAssoc +let setAssocU = setAssoc +let some2U = some2 +let someU = some +let sortU = sort +let zipByU = zipBy diff --git a/belt/src/belt_List.resi b/belt/src/belt_List.resi index 86ad8d7..6a29b27 100644 --- a/belt/src/belt_List.resi +++ b/belt/src/belt_List.resi @@ -161,6 +161,7 @@ Belt.List.make(3, 1) // list{1, 1, 1} let make: (int, 'a) => t<'a> /** Uncurried version of [makeBy](#makeBy) */ +@deprecated("Use `makeBy` instead") let makeByU: (int, int => 'a) => t<'a> /** @@ -277,6 +278,7 @@ Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} let flatten: t> => t<'a> /** Uncurried version of [map](#map). */ +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => t<'b> /** @@ -302,6 +304,7 @@ Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} let zip: (t<'a>, t<'b>) => t<('a, 'b)> /** Uncurried version of [zipBy](#zipBy). */ +@deprecated("Use `zipBy` instead") let zipByU: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> /** @@ -316,6 +319,7 @@ Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} let zipBy: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> /** Uncurried version of [mapWithIndex](#mapWithIndex). */ +@deprecated("Use `mapWithIndex` instead") let mapWithIndexU: (t<'a>, (int, 'a) => 'b) => t<'b> /** @@ -369,6 +373,7 @@ Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ let reverse: t<'a> => t<'a> /** Uncurried version of [mapReverse](#mapReverse). */ +@deprecated("Use `mapReverse` instead") let mapReverseU: (t<'a>, 'a => 'b) => t<'b> /** @@ -387,6 +392,7 @@ list{3, 4, 5}->Belt.List.mapReverse(x => x * x) /* list{25, 16, 9} */ let mapReverse: (t<'a>, 'a => 'b) => t<'b> /** Uncurried version of [forEach](#forEach). */ +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, 'a => 'b) => unit /** @@ -408,6 +414,7 @@ Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) let forEach: (t<'a>, 'a => 'b) => unit /** Uncurried version of [forEachWithIndex](#forEachWithIndex). */ +@deprecated("Use `forEachWithIndex` instead") let forEachWithIndexU: (t<'a>, (int, 'a) => 'b) => unit /** @@ -431,6 +438,7 @@ Belt.List.forEachWithIndex(list{"a", "b", "c"}, (index, x) => { let forEachWithIndex: (t<'a>, (int, 'a) => 'b) => unit /** Uncurried version of [reduce](#reduce). */ +@deprecated("Use `reduce` instead") let reduceU: (t<'a>, 'b, ('b, 'a) => 'b) => 'b /** @@ -449,6 +457,7 @@ list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ let reduce: (t<'a>, 'b, ('b, 'a) => 'b) => 'b /** Uncurried version of [reduceWithIndex](#reduceWithIndex). */ +@deprecated("Use `reduceWithIndex` instead") let reduceWithIndexU: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b /** @@ -463,6 +472,7 @@ list{1, 2, 3, 4}->Belt.List.reduceWithIndex(0, (acc, item, index) => acc + item let reduceWithIndex: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b /** Uncurried version of [reduceReverse](#reduceReverse). */ +@deprecated("Use `reduceReverse` instead") let reduceReverseU: (t<'a>, 'b, ('b, 'a) => 'b) => 'b /** @@ -482,6 +492,7 @@ list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3 let reduceReverse: (t<'a>, 'b, ('b, 'a) => 'b) => 'b /** Uncurried version of [mapReverse2](#mapReverse2). */ +@deprecated("Use `mapReverse2` instead") let mapReverse2U: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> /** @@ -497,6 +508,7 @@ Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} let mapReverse2: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> /** Uncurried version of [forEach2](#forEach2). */ +@deprecated("Use `forEach2` instead") let forEach2U: (t<'a>, t<'b>, ('a, 'b) => 'c) => unit /** @@ -517,6 +529,7 @@ Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) let forEach2: (t<'a>, t<'b>, ('a, 'b) => 'c) => unit /** Uncurried version of [reduce2](#reduce2). */ +@deprecated("Use `reduce2` instead") let reduce2U: (t<'b>, t<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a /** @@ -531,6 +544,7 @@ Belt.List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) let reduce2: (t<'b>, t<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a /** Uncurried version of [reduceReverse2](#reduceReverse2). */ +@deprecated("Use `reduceReverse2` instead") let reduceReverse2U: (t<'a>, t<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c /** @@ -549,6 +563,7 @@ Belt.List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * let reduceReverse2: (t<'a>, t<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c /** Uncurried version of [every](#every). */ +@deprecated("Use `every` instead") let everyU: (t<'a>, 'a => bool) => bool /** @@ -567,6 +582,7 @@ list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ let every: (t<'a>, 'a => bool) => bool /** Uncurried version of [some](#some). */ +@deprecated("Use `some` instead") let someU: (t<'a>, 'a => bool) => bool /** @@ -587,6 +603,7 @@ list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ let some: (t<'a>, 'a => bool) => bool /** Uncurried version of [every2](#every2). */ +@deprecated("Use `every2` instead") let every2U: (t<'a>, t<'b>, ('a, 'b) => bool) => bool /** @@ -608,6 +625,7 @@ Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ let every2: (t<'a>, t<'b>, ('a, 'b) => bool) => bool /** Uncurried version of [some2](#some2). */ +@deprecated("Use `some2` instead") let some2U: (t<'a>, t<'b>, ('a, 'b) => bool) => bool /** @@ -647,6 +665,7 @@ Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ let cmpByLength: (t<'a>, t<'a>) => int /** Uncurried version of [cmp](#cmp). */ +@deprecated("Use `cmp` instead") let cmpU: (t<'a>, t<'a>, ('a, 'a) => int) => int /** @@ -678,6 +697,7 @@ For lists, we just compare elements one by one. let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int /** Uncurried version of [eq](#eq). */ +@deprecated("Use `eq` instead") let eqU: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** @@ -699,6 +719,7 @@ Belt.List.eq(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)) let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** Uncurried version of [has](#has). */ +@deprecated("Use `has` instead") let hasU: (t<'a>, 'b, ('a, 'b) => bool) => bool /** @@ -718,6 +739,7 @@ list{(-1), (-2), (-3)}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ let has: (t<'a>, 'b, ('a, 'b) => bool) => bool /** Uncurried version of [getBy](#getBy). */ +@deprecated("Use `getBy` instead") let getByU: (t<'a>, 'a => bool) => option<'a> /** @@ -735,6 +757,7 @@ Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ let getBy: (t<'a>, 'a => bool) => option<'a> /** Uncurried version of [keep](#keep). */ +@deprecated("Use `keep` instead") let keepU: (t<'a>, 'a => bool) => t<'a> /** @@ -769,6 +792,7 @@ Belt.List.filter(list{None, Some(2), Some(3), None}, Belt.Option.isSome) /* list let filter: (t<'a>, 'a => bool) => t<'a> /** Uncurried version of [keepWithIndex](#keepWithIndex). */ +@deprecated("Use `keepWithIndex` instead") let keepWithIndexU: (t<'a>, ('a, int) => bool) => t<'a> /** @@ -802,6 +826,7 @@ Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* lis let filterWithIndex: (t<'a>, ('a, int) => bool) => t<'a> /** Uncurried version of [keepMap](#keepMap). */ +@deprecated("Use `keepMap` instead") let keepMapU: (t<'a>, 'a => option<'b>) => t<'b> /** @@ -828,6 +853,7 @@ list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ let keepMap: (t<'a>, 'a => option<'b>) => t<'b> /** Uncurried version of [partition](#partition). */ +@deprecated("Use `partition` instead") let partitionU: (t<'a>, 'a => bool) => (t<'a>, t<'a>) /** @@ -862,6 +888,7 @@ Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), let unzip: t<('a, 'b)> => (t<'a>, t<'b>) /** Uncurried version of [getAssoc](#getAssoc). */ +@deprecated("Use `getAssoc` instead") let getAssocU: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c> /** @@ -880,6 +907,7 @@ list{(9, "morning"), (15, "afternoon"), (22, "night")} let getAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c> /** Uncurried version of [hasAssoc](#hasAssoc). */ +@deprecated("Use `hasAssoc` instead") let hasAssocU: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool /** @@ -897,6 +925,7 @@ list{(9, "morning"), (15, "afternoon"), (22, "night")} let hasAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool /** Uncurried version of [removeAssoc](#removeAssoc). */ +@deprecated("Use `removeAssoc` instead") let removeAssocU: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)> /** @@ -915,6 +944,7 @@ list{(9, "morning"), (15, "afternoon"), (22, "night")} let removeAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)> /** Uncurried version of [setAssoc](#setAssoc). */ +@deprecated("Use `setAssoc` instead") let setAssocU: (t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)> /** @@ -941,6 +971,7 @@ Both the key _and_ the value are replaced in the list. let setAssoc: (t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)> /** Uncurried version of [sort](#sort). */ +@deprecated("Use `sort` instead") let sortU: (t<'a>, ('a, 'a) => int) => t<'a> /** diff --git a/belt/src/belt_Map.js b/belt/src/belt_Map.js index 095b87f..ef54980 100644 --- a/belt/src/belt_Map.js +++ b/belt/src/belt_Map.js @@ -49,20 +49,14 @@ function mergeMany(m, e) { }; } -function updateU(m, key, f) { +function update(m, key, f) { let cmp = m.cmp; return { cmp: cmp, - data: Belt_MapDict.updateU(m.data, key, f, cmp) + data: Belt_MapDict.update(m.data, key, f, cmp) }; } -function update(m, key, f) { - return updateU(m, key, (function (a) { - return f(a); - })); -} - function split(m, x) { let cmp = m.cmp; let match = Belt_MapDict.split(m.data, x, cmp); @@ -82,20 +76,14 @@ function split(m, x) { ]; } -function mergeU(s1, s2, f) { +function merge(s1, s2, f) { let cmp = s1.cmp; return { cmp: cmp, - data: Belt_MapDict.mergeU(s1.data, s2.data, f, cmp) + data: Belt_MapDict.merge(s1.data, s2.data, f, cmp) }; } -function merge(s1, s2, f) { - return mergeU(s1, s2, (function (a, b, c) { - return f(a, b, c); - })); -} - function make(id) { return { cmp: id.cmp, @@ -107,72 +95,36 @@ function isEmpty(map) { return Belt_MapDict.isEmpty(map.data); } -function findFirstByU(m, f) { - return Belt_MapDict.findFirstByU(m.data, f); -} - function findFirstBy(m, f) { - return Belt_MapDict.findFirstByU(m.data, (function (a, b) { - return f(a, b); - })); -} - -function forEachU(m, f) { - Belt_MapDict.forEachU(m.data, f); + return Belt_MapDict.findFirstBy(m.data, f); } function forEach(m, f) { - Belt_MapDict.forEachU(m.data, (function (a, b) { - f(a, b); - })); -} - -function reduceU(m, acc, f) { - return Belt_MapDict.reduceU(m.data, acc, f); + Belt_MapDict.forEach(m.data, f); } function reduce(m, acc, f) { - return reduceU(m, acc, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(m, f) { - return Belt_MapDict.everyU(m.data, f); + return Belt_MapDict.reduce(m.data, acc, f); } function every(m, f) { - return Belt_MapDict.everyU(m.data, (function (a, b) { - return f(a, b); - })); -} - -function someU(m, f) { - return Belt_MapDict.someU(m.data, f); + return Belt_MapDict.every(m.data, f); } function some(m, f) { - return Belt_MapDict.someU(m.data, (function (a, b) { - return f(a, b); - })); + return Belt_MapDict.some(m.data, f); } -function keepU(m, f) { +function keep(m, f) { return { cmp: m.cmp, - data: Belt_MapDict.keepU(m.data, f) + data: Belt_MapDict.keep(m.data, f) }; } -function keep(m, f) { - return keepU(m, (function (a, b) { - return f(a, b); - })); -} - -function partitionU(m, p) { +function partition(m, p) { let cmp = m.cmp; - let match = Belt_MapDict.partitionU(m.data, p); + let match = Belt_MapDict.partition(m.data, p); return [ { cmp: cmp, @@ -185,38 +137,20 @@ function partitionU(m, p) { ]; } -function partition(m, p) { - return partitionU(m, (function (a, b) { - return p(a, b); - })); -} - -function mapU(m, f) { +function map(m, f) { return { cmp: m.cmp, - data: Belt_MapDict.mapU(m.data, f) + data: Belt_MapDict.map(m.data, f) }; } -function map(m, f) { - return mapU(m, (function (a) { - return f(a); - })); -} - -function mapWithKeyU(m, f) { +function mapWithKey(m, f) { return { cmp: m.cmp, - data: Belt_MapDict.mapWithKeyU(m.data, f) + data: Belt_MapDict.mapWithKey(m.data, f) }; } -function mapWithKey(m, f) { - return mapWithKeyU(m, (function (a, b) { - return f(a, b); - })); -} - function size(map) { return Belt_MapDict.size(map.data); } @@ -293,24 +227,12 @@ function checkInvariantInternal(m) { Belt_MapDict.checkInvariantInternal(m.data); } -function eqU(m1, m2, veq) { - return Belt_MapDict.eqU(m1.data, m2.data, m1.cmp, veq); -} - function eq(m1, m2, veq) { - return eqU(m1, m2, (function (a, b) { - return veq(a, b); - })); -} - -function cmpU(m1, m2, vcmp) { - return Belt_MapDict.cmpU(m1.data, m2.data, m1.cmp, vcmp); + return Belt_MapDict.eq(m1.data, m2.data, m1.cmp, veq); } function cmp(m1, m2, vcmp) { - return cmpU(m1, m2, (function (a, b) { - return vcmp(a, b); - })); + return Belt_MapDict.cmp(m1.data, m2.data, m1.cmp, vcmp); } function getData(m) { @@ -337,6 +259,32 @@ let $$String; let Dict; +let cmpU = cmp; + +let eqU = eq; + +let findFirstByU = findFirstBy; + +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let updateU = update; + +let mergeU = merge; + +let keepU = keep; + +let partitionU = partition; + +let mapU = map; + +let mapWithKeyU = mapWithKey; + export { Int, $$String, diff --git a/belt/src/belt_Map.res b/belt/src/belt_Map.res index 3f82c33..df8f055 100644 --- a/belt/src/belt_Map.res +++ b/belt/src/belt_Map.res @@ -66,24 +66,21 @@ let mergeMany = (m, e) => { {cmp, data: Dict.mergeMany(~cmp, m.data, e)} } -let updateU = (m, key, f) => { +let update = (m, key, f) => { let cmp = m.cmp - {cmp, data: Dict.updateU(~cmp, m.data, key, f)} + {cmp, data: Dict.update(~cmp, m.data, key, f)} } -let update = (m, key, f) => updateU(m, key, a => f(a)) let split = (m, x) => { let cmp = m.cmp let ((l, r), b) = Dict.split(~cmp, m.data, x) (({cmp, data: l}, {cmp, data: r}), b) } -let mergeU = (s1, s2, f) => { +let merge = (s1, s2, f) => { let cmp = s1.cmp - {cmp, data: Dict.mergeU(~cmp, s1.data, s2.data, f)} + {cmp, data: Dict.merge(~cmp, s1.data, s2.data, f)} } -let merge = (s1, s2, f) => mergeU(s1, s2, (a, b, c) => f(a, b, c)) - let make = (type key idx, ~id: id) => { module M = unpack(id) {cmp: M.cmp, data: Dict.empty} @@ -91,30 +88,21 @@ let make = (type key idx, ~id: id) => { let isEmpty = map => Dict.isEmpty(map.data) -let findFirstByU = (m, f) => Dict.findFirstByU(m.data, f) -let findFirstBy = (m, f) => findFirstByU(m, (a, b) => f(a, b)) -let forEachU = (m, f) => Dict.forEachU(m.data, f) -let forEach = (m, f) => forEachU(m, (a, b) => f(a, b)) -let reduceU = (m, acc, f) => Dict.reduceU(m.data, acc, f) -let reduce = (m, acc, f) => reduceU(m, acc, (a, b, c) => f(a, b, c)) -let everyU = (m, f) => Dict.everyU(m.data, f) -let every = (m, f) => everyU(m, (a, b) => f(a, b)) -let someU = (m, f) => Dict.someU(m.data, f) -let some = (m, f) => someU(m, (a, b) => f(a, b)) -let keepU = (m, f) => {cmp: m.cmp, data: Dict.keepU(m.data, f)} -let keep = (m, f) => keepU(m, (a, b) => f(a, b)) - -let partitionU = (m, p) => { +let findFirstBy = (m, f) => Dict.findFirstBy(m.data, f) +let forEach = (m, f) => Dict.forEach(m.data, f) +let reduce = (m, acc, f) => Dict.reduce(m.data, acc, f) +let every = (m, f) => Dict.every(m.data, f) +let some = (m, f) => Dict.some(m.data, f) +let keep = (m, f) => {cmp: m.cmp, data: Dict.keep(m.data, f)} + +let partition = (m, p) => { let cmp = m.cmp - let (l, r) = m.data->Dict.partitionU(p) + let (l, r) = m.data->Dict.partition(p) ({cmp, data: l}, {cmp, data: r}) } -let partition = (m, p) => partitionU(m, (a, b) => p(a, b)) -let mapU = (m, f) => {cmp: m.cmp, data: Dict.mapU(m.data, f)} -let map = (m, f) => mapU(m, a => f(a)) -let mapWithKeyU = (m, f) => {cmp: m.cmp, data: Dict.mapWithKeyU(m.data, f)} -let mapWithKey = (m, f) => mapWithKeyU(m, (a, b) => f(a, b)) +let map = (m, f) => {cmp: m.cmp, data: Dict.map(m.data, f)} +let mapWithKey = (m, f) => {cmp: m.cmp, data: Dict.mapWithKey(m.data, f)} let size = map => Dict.size(map.data) let toList = map => Dict.toList(map.data) let toArray = m => Dict.toArray(m.data) @@ -141,11 +129,9 @@ let has = (map, x) => Dict.has(~cmp=map.cmp, map.data, x) let checkInvariantInternal = m => Dict.checkInvariantInternal(m.data) -let eqU = (m1, m2, veq) => Dict.eqU(~kcmp=m1.cmp, ~veq, m1.data, m2.data) -let eq = (m1, m2, veq) => eqU(m1, m2, (a, b) => veq(a, b)) +let eq = (m1, m2, veq) => Dict.eq(~kcmp=m1.cmp, ~veq, m1.data, m2.data) -let cmpU = (m1, m2, vcmp) => Dict.cmpU(~kcmp=m1.cmp, ~vcmp, m1.data, m2.data) -let cmp = (m1, m2, vcmp) => cmpU(m1, m2, (a, b) => vcmp(a, b)) +let cmp = (m1, m2, vcmp) => Dict.cmp(~kcmp=m1.cmp, ~vcmp, m1.data, m2.data) let getData = m => m.data @@ -162,3 +148,17 @@ let packIdData = (type key idx, ~id: id, ~data) => { module M = unpack(id) {cmp: M.cmp, data} } + +let cmpU = cmp +let eqU = eq +let everyU = every +let findFirstByU = findFirstBy +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithKeyU = mapWithKey +let mergeU = merge +let partitionU = partition +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_Map.resi b/belt/src/belt_Map.resi index 9c84a01..59841d8 100644 --- a/belt/src/belt_Map.resi +++ b/belt/src/belt_Map.resi @@ -96,6 +96,7 @@ Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true */ let has: (t<'k, 'v, 'id>, 'k) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ('v, 'v) => int) => int /** `cmp(m0, m1, vcmp);` @@ -106,6 +107,7 @@ It will compare size first and each element following the order one by one. */ let cmp: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ('v, 'v) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ('v, 'v) => bool) => bool /** eq(m1, m2, veq)` tests whether the maps `m1` and `m2` are equal, that is, @@ -114,6 +116,7 @@ equality predicate used to compare the data associated with the keys. */ let eq: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ('v, 'v) => bool) => bool +@deprecated("Use `findFirstBy` instead") let findFirstByU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> /** ` findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`. @@ -133,6 +136,7 @@ Belt.Map.findFirstBy(s0, (k, v) => k == 4) /* (4, "4") */ */ let findFirstBy: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> +@deprecated("Use `forEach` instead") let forEachU: (t<'k, 'v, 'id>, ('k, 'v) => unit) => unit /** `forEach(m, f)` applies `f` to all bindings in map `m`. `f` receives the @@ -159,6 +163,7 @@ acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} */ let forEach: (t<'k, 'v, 'id>, ('k, 'v) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'k, 'v, 'id>, 'acc, ('acc, 'k, 'v) => 'acc) => 'acc /** `reduce(m, a, f)` computes `(f(kN, dN) ... (f(k1, d1, a))...)`, where `k1 @@ -183,6 +188,7 @@ Belt.Map.reduce(s0, list{}, (acc, k, v) => list{ */ let reduce: (t<'k, 'v, 'id>, 'acc, ('acc, 'k, 'v) => 'acc) => 'acc +@deprecated("Use `every` instead") let everyU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => bool /** `every(m, p)` checks if all the bindings of the map satisfy the predicate @@ -190,6 +196,7 @@ let everyU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => bool */ let every: (t<'k, 'v, 'id>, ('k, 'v) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => bool /** `some(m, p)` checks if at least one binding of the map satisfy the predicate @@ -413,6 +420,7 @@ Belt.Map.valuesToArray(s1) == ["1", "3", "3"] */ let set: (t<'k, 'v, 'id>, 'k, 'v) => t<'k, 'v, 'id> +@deprecated("Use `update` instead") let updateU: (t<'k, 'v, 'id>, 'k, option<'v> => option<'v>) => t<'k, 'v, 'id> /** `update(m, x, f)` returns a map containing the same bindings as `m`, except @@ -431,6 +439,7 @@ value might be changed even if all values in `xs` exist `s`. */ let mergeMany: (t<'k, 'v, 'id>, array<('k, 'v)>) => t<'k, 'v, 'id> +@deprecated("Use `merge` instead") let mergeU: ( t<'k, 'v, 'id>, t<'k, 'v2, 'id>, @@ -447,6 +456,7 @@ let merge: ( ('k, option<'v>, option<'v2>) => option<'v3>, ) => t<'k, 'v3, 'id> +@deprecated("Use `keep` instead") let keepU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => t<'k, 'v, 'id> /** `keep(m, p)` returns the map with all the bindings in m that satisfy @@ -454,6 +464,7 @@ predicate `p`. */ let keep: (t<'k, 'v, 'id>, ('k, 'v) => bool) => t<'k, 'v, 'id> +@deprecated("Use `partition` instead") let partitionU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => (t<'k, 'v, 'id>, t<'k, 'v, 'id>) /** `partition(m, p)` returns a pair of maps `(m1, m2)`, where `m1` contains @@ -471,6 +482,7 @@ all the bindings of m whose 'k is strictly greater than `x`; `data` is */ let split: (t<'k, 'v, 'id>, 'k) => ((t<'k, 'v, 'id>, t<'k, 'v, 'id>), option<'v>) +@deprecated("Use `map` instead") let mapU: (t<'k, 'v, 'id>, 'v => 'v2) => t<'k, 'v2, 'id> /** `map(m, f) returns a map with same domain as`m`, where the associated @@ -480,6 +492,7 @@ with respect to the ordering over the type of the keys. */ let map: (t<'k, 'v, 'id>, 'v => 'v2) => t<'k, 'v2, 'id> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'k, 'v, 'id>, ('k, 'v) => 'v2) => t<'k, 'v2, 'id> /** `mapWithKey(m, f)` diff --git a/belt/src/belt_MapDict.js b/belt/src/belt_MapDict.js index f4b5b4e..a0c6d56 100644 --- a/belt/src/belt_MapDict.js +++ b/belt/src/belt_MapDict.js @@ -22,7 +22,7 @@ function set(t, newK, newD, cmp) { } } -function updateU(t, newK, f, cmp) { +function update(t, newK, f, cmp) { if (t !== undefined) { let k = t.k; let c = cmp(newK, k); @@ -52,14 +52,14 @@ function updateU(t, newK, f, cmp) { let r$2 = t.r; let v = t.v; if (c < 0) { - let ll = updateU(l$1, newK, f, cmp); + let ll = update(l$1, newK, f, cmp); if (l$1 === ll) { return t; } else { return Belt_internalAVLtree.bal(ll, k, v, r$2); } } - let rr = updateU(r$2, newK, f, cmp); + let rr = update(r$2, newK, f, cmp); if (r$2 === rr) { return t; } else { @@ -74,12 +74,6 @@ function updateU(t, newK, f, cmp) { } } -function update(t, newK, f, cmp) { - return updateU(t, newK, (function (a) { - return f(a); - }), cmp); -} - function removeAux0(n, x, cmp) { let v = n.k; let l = n.l; @@ -199,10 +193,10 @@ function split(n, x, cmp) { ]; } -function mergeU(s1, s2, f, cmp) { +function merge(s1, s2, f, cmp) { if (s1 === undefined) { if (s2 !== undefined) { - return Belt_internalAVLtree.keepMapU(s2, (function (k, v) { + return Belt_internalAVLtree.keepMap(s2, (function (k, v) { return f(k, undefined, Caml_option.some(v)); })); } else { @@ -210,7 +204,7 @@ function mergeU(s1, s2, f, cmp) { } } if (s2 === undefined) { - return Belt_internalAVLtree.keepMapU(s1, (function (k, v) { + return Belt_internalAVLtree.keepMap(s1, (function (k, v) { return f(k, Caml_option.some(v), undefined); })); } @@ -224,9 +218,9 @@ function mergeU(s1, s2, f, cmp) { }; let match = splitAuxPivot(s2, v1, d2, cmp); let d2$1 = d2.contents; - let newLeft = mergeU(l1, match[0], f, cmp); + let newLeft = merge(l1, match[0], f, cmp); let newD = f(v1, Caml_option.some(d1), d2$1); - let newRight = mergeU(r1, match[1], f, cmp); + let newRight = merge(r1, match[1], f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft, v1, newD, newRight); } let v2 = s2.k; @@ -238,18 +232,12 @@ function mergeU(s1, s2, f, cmp) { }; let match$1 = splitAuxPivot(s1, v2, d1$1, cmp); let d1$2 = d1$1.contents; - let newLeft$1 = mergeU(match$1[0], l2, f, cmp); + let newLeft$1 = merge(match$1[0], l2, f, cmp); let newD$1 = f(v2, d1$2, Caml_option.some(d2$2)); - let newRight$1 = mergeU(match$1[1], r2, f, cmp); + let newRight$1 = merge(match$1[1], r2, f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft$1, v2, newD$1, newRight$1); } -function merge(s1, s2, f, cmp) { - return mergeU(s1, s2, (function (a, b, c) { - return f(a, b, c); - }), cmp); -} - function removeMany(t, keys, cmp) { let len = keys.length; if (t !== undefined) { @@ -280,31 +268,31 @@ let isEmpty = Belt_internalAVLtree.isEmpty; let has = Belt_internalAVLtree.has; -let cmpU = Belt_internalAVLtree.cmpU; +let cmpU = Belt_internalAVLtree.cmp; let cmp = Belt_internalAVLtree.cmp; -let eqU = Belt_internalAVLtree.eqU; +let eqU = Belt_internalAVLtree.eq; let eq = Belt_internalAVLtree.eq; -let findFirstByU = Belt_internalAVLtree.findFirstByU; +let findFirstByU = Belt_internalAVLtree.findFirstBy; let findFirstBy = Belt_internalAVLtree.findFirstBy; -let forEachU = Belt_internalAVLtree.forEachU; +let forEachU = Belt_internalAVLtree.forEach; let forEach = Belt_internalAVLtree.forEach; -let reduceU = Belt_internalAVLtree.reduceU; +let reduceU = Belt_internalAVLtree.reduce; let reduce = Belt_internalAVLtree.reduce; -let everyU = Belt_internalAVLtree.everyU; +let everyU = Belt_internalAVLtree.every; let every = Belt_internalAVLtree.every; -let someU = Belt_internalAVLtree.someU; +let someU = Belt_internalAVLtree.some; let some = Belt_internalAVLtree.some; @@ -346,19 +334,23 @@ let getExn = Belt_internalAVLtree.getExn; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; -let keepU = Belt_internalAVLtree.keepSharedU; +let updateU = update; + +let mergeU = merge; + +let keepU = Belt_internalAVLtree.keepShared; let keep = Belt_internalAVLtree.keepShared; -let partitionU = Belt_internalAVLtree.partitionSharedU; +let partitionU = Belt_internalAVLtree.partitionShared; let partition = Belt_internalAVLtree.partitionShared; -let mapU = Belt_internalAVLtree.mapU; +let mapU = Belt_internalAVLtree.map; let map = Belt_internalAVLtree.map; -let mapWithKeyU = Belt_internalAVLtree.mapWithKeyU; +let mapWithKeyU = Belt_internalAVLtree.mapWithKey; let mapWithKey = Belt_internalAVLtree.mapWithKey; diff --git a/belt/src/belt_MapDict.res b/belt/src/belt_MapDict.res index e73af24..1472d96 100644 --- a/belt/src/belt_MapDict.res +++ b/belt/src/belt_MapDict.res @@ -33,19 +33,14 @@ let empty = None let fromArray = N.fromArray let isEmpty = N.isEmpty let cmp = N.cmp -let cmpU = N.cmpU let eq = N.eq -let eqU = N.eqU let has = N.has +let findFirstBy = N.findFirstBy let forEach = N.forEach -let forEachU = N.forEachU let reduce = N.reduce -let reduceU = N.reduceU let every = N.every -let everyU = N.everyU let some = N.some -let someU = N.someU let size = N.size let toList = N.toList @@ -67,13 +62,9 @@ let getWithDefault = N.getWithDefault let getExn = N.getExn let mapWithKey = N.mapWithKey -let mapWithKeyU = N.mapWithKeyU -let mapU = N.mapU let map = N.map let keep = N.keepShared -let keepU = N.keepSharedU -let partitionU = N.partitionSharedU let partition = N.partitionShared let checkInvariantInternal = N.checkInvariantInternal let rec set = (t: t<_>, newK, newD, ~cmp) => @@ -95,7 +86,7 @@ let rec set = (t: t<_>, newK, newD, ~cmp) => } } -let rec updateU = (t: t<_>, newK, f, ~cmp): t<_> => +let rec update = (t: t<_>, newK, f, ~cmp): t<_> => switch t { | None => switch f(None) { @@ -122,14 +113,14 @@ let rec updateU = (t: t<_>, newK, f, ~cmp): t<_> => } else { let (l, r, v) = (n.N.left, n.N.right, n.N.value) if c < 0 { - let ll = updateU(~cmp, l, newK, f) + let ll = update(~cmp, l, newK, f) if l === ll { t } else { N.bal(ll, k, v, r) } } else { - let rr = updateU(~cmp, r, newK, f) + let rr = update(~cmp, r, newK, f) if r === rr { t } else { @@ -139,8 +130,6 @@ let rec updateU = (t: t<_>, newK, f, ~cmp): t<_> => } } -let update = (t, newK, f, ~cmp) => updateU(t, newK, a => f(a), ~cmp) - /* unboxing API was not exported since the correct API is really awkard `bool -> 'k Js.null -> ('a Js.null * bool)` @@ -241,38 +230,33 @@ let split = (n, x, ~cmp) => (v, pres.contents) } -let findFirstByU = N.findFirstByU -let findFirstBy = N.findFirstBy - -let rec mergeU = (s1, s2, f, ~cmp) => +let rec merge = (s1, s2, f, ~cmp) => switch (s1, s2) { | (None, None) => None - | (Some(_), None) => N.keepMapU(s1, (k, v) => f(k, Some(v), None)) - | (None, Some(_)) => N.keepMapU(s2, (k, v) => f(k, None, Some(v))) + | (Some(_), None) => N.keepMap(s1, (k, v) => f(k, Some(v), None)) + | (None, Some(_)) => N.keepMap(s2, (k, v) => f(k, None, Some(v))) | (Some(s1n), Some(s2n)) => if s1n.height >= s2n.height { let {N.left: l1, key: v1, value: d1, right: r1} = s1n let d2 = ref(None) let (l2, r2) = splitAuxPivot(~cmp, s2n, v1, d2) let d2 = d2.contents - let newLeft = mergeU(~cmp, l1, l2, f) + let newLeft = merge(~cmp, l1, l2, f) let newD = f(v1, Some(d1), d2) - let newRight = mergeU(~cmp, r1, r2, f) + let newRight = merge(~cmp, r1, r2, f) N.concatOrJoin(newLeft, v1, newD, newRight) } else { let {N.left: l2, key: v2, value: d2, right: r2} = s2n let d1 = ref(None) let (l1, r1) = splitAuxPivot(~cmp, s1n, v2, d1) let d1 = d1.contents - let newLeft = mergeU(~cmp, l1, l2, f) + let newLeft = merge(~cmp, l1, l2, f) let newD = f(v2, d1, Some(d2)) - let newRight = mergeU(~cmp, r1, r2, f) + let newRight = merge(~cmp, r1, r2, f) N.concatOrJoin(newLeft, v2, newD, newRight) } } -let merge = (s1, s2, f, ~cmp) => mergeU(s1, s2, (a, b, c) => f(a, b, c), ~cmp) - let rec removeMany0 = (t, xs, i, len, ~cmp) => if i < len { let ele = A.getUnsafe(xs, i) @@ -292,3 +276,17 @@ let removeMany = (t, keys, ~cmp) => { | Some(t) => removeMany0(t, keys, 0, len, ~cmp) } } + +let cmpU = cmp +let eqU = eq +let everyU = every +let findFirstByU = findFirstBy +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithKeyU = mapWithKey +let mergeU = merge +let partitionU = partition +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MapDict.resi b/belt/src/belt_MapDict.resi index 96862ce..15590a2 100644 --- a/belt/src/belt_MapDict.resi +++ b/belt/src/belt_MapDict.resi @@ -49,9 +49,11 @@ let isEmpty: t<'k, 'v, 'id> => bool let has: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ~kcmp: cmp<'k, 'id>, ~vcmp: ('v, 'v) => int) => int let cmp: (t<'k, 'v, 'id>, t<'k, 'v, 'id>, ~kcmp: cmp<'k, 'id>, ~vcmp: ('v, 'v) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ~kcmp: cmp<'k, 'id>, ~veq: ('a, 'a) => bool) => bool /** `eq(m1, m2, cmp)` tests whether the maps `m1` and `m2` are equal, that is, @@ -60,6 +62,7 @@ equality predicate used to compare the data associated with the keys. */ let eq: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ~kcmp: cmp<'k, 'id>, ~veq: ('a, 'a) => bool) => bool +@deprecated("Use `findFirstBy` instead") let findFirstByU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> /** `findFirstBy(m, p)` uses function `f` to find the first key value pair to @@ -80,6 +83,7 @@ Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) */ let findFirstBy: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> +@deprecated("Use `forEach` instead") let forEachU: (t<'k, 'a, 'id>, ('k, 'a) => unit) => unit /** `forEach(m, f)` applies `f` to all bindings in map `m`. `f` receives the @@ -89,6 +93,7 @@ over the type of the keys. */ let forEach: (t<'k, 'a, 'id>, ('k, 'a) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'k, 'a, 'id>, 'b, ('b, 'k, 'a) => 'b) => 'b /** `reduce(m, a, f)` computes `f(kN, dN ... f(k1, d1, a)...)`, where `k1 ... kN` @@ -97,6 +102,7 @@ are the associated data. */ let reduce: (t<'k, 'a, 'id>, 'b, ('b, 'k, 'a) => 'b) => 'b +@deprecated("Use `every` instead") let everyU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool /** `every(m, p)` checks if all the bindings of the map satisfy the predicate @@ -104,6 +110,7 @@ let everyU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool */ let every: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool /** `some(m, p)` checks if at least one binding of the map satisfy the @@ -165,9 +172,11 @@ binding disappears. */ let set: (t<'a, 'b, 'id>, 'a, 'b, ~cmp: cmp<'a, 'id>) => t<'a, 'b, 'id> +@deprecated("Use `update` instead") let updateU: (t<'a, 'b, 'id>, 'a, option<'b> => option<'b>, ~cmp: cmp<'a, 'id>) => t<'a, 'b, 'id> let update: (t<'a, 'b, 'id>, 'a, option<'b> => option<'b>, ~cmp: cmp<'a, 'id>) => t<'a, 'b, 'id> +@deprecated("Use `merge` instead") let mergeU: ( t<'a, 'b, 'id>, t<'a, 'c, 'id>, @@ -188,6 +197,7 @@ let merge: ( let mergeMany: (t<'a, 'b, 'id>, array<('a, 'b)>, ~cmp: cmp<'a, 'id>) => t<'a, 'b, 'id> +@deprecated("Use `keep` instead") let keepU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => t<'k, 'a, 'id> /** `keep(m, p)` returns the map with all the bindings in `m` that satisfy @@ -195,6 +205,7 @@ predicate `p`. */ let keep: (t<'k, 'a, 'id>, ('k, 'a) => bool) => t<'k, 'a, 'id> +@deprecated("Use `partition` instead") let partitionU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => (t<'k, 'a, 'id>, t<'k, 'a, 'id>) /** `partition(m, p)` returns a pair of maps `(m1, m2)`, where `m1` contains @@ -216,6 +227,7 @@ let split: ( ~cmp: cmp<'a, 'id>, ) => ((t<'a, 'b, 'id>, t<'a, 'b, 'id>), option<'b>) +@deprecated("Use `map` instead") let mapU: (t<'k, 'a, 'id>, 'a => 'b) => t<'k, 'b, 'id> /** `map(m, f)` returns a map with same domain as `m`, where the associated @@ -225,5 +237,6 @@ order with respect to the ordering over the type of the keys. */ let map: (t<'k, 'a, 'id>, 'a => 'b) => t<'k, 'b, 'id> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id> let mapWithKey: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id> diff --git a/belt/src/belt_MapInt.js b/belt/src/belt_MapInt.js index a5107f8..e149988 100644 --- a/belt/src/belt_MapInt.js +++ b/belt/src/belt_MapInt.js @@ -20,7 +20,7 @@ function set(t, newK, newD) { } } -function updateU(t, x, f) { +function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { @@ -49,14 +49,14 @@ function updateU(t, x, f) { let l$1 = t.l; let r$2 = t.r; if (x < k) { - let ll = updateU(l$1, x, f); + let ll = update(l$1, x, f); if (l$1 === ll) { return t; } else { return Belt_internalAVLtree.bal(ll, k, v, r$2); } } - let rr = updateU(r$2, x, f); + let rr = update(r$2, x, f); if (r$2 === rr) { return t; } else { @@ -71,12 +71,6 @@ function updateU(t, x, f) { } } -function update(t, x, f) { - return updateU(t, x, (function (a) { - return f(a); - })); -} - function removeAux(n, x) { let v = n.k; let l = n.l; @@ -162,31 +156,31 @@ let isEmpty = Belt_internalAVLtree.isEmpty; let has = Belt_internalMapInt.has; -let cmpU = Belt_internalMapInt.cmpU; +let cmpU = Belt_internalMapInt.cmp; let cmp = Belt_internalMapInt.cmp; -let eqU = Belt_internalMapInt.eqU; +let eqU = Belt_internalMapInt.eq; let eq = Belt_internalMapInt.eq; -let findFirstByU = Belt_internalAVLtree.findFirstByU; +let findFirstByU = Belt_internalAVLtree.findFirstBy; let findFirstBy = Belt_internalAVLtree.findFirstBy; -let forEachU = Belt_internalAVLtree.forEachU; +let forEachU = Belt_internalAVLtree.forEach; let forEach = Belt_internalAVLtree.forEach; -let reduceU = Belt_internalAVLtree.reduceU; +let reduceU = Belt_internalAVLtree.reduce; let reduce = Belt_internalAVLtree.reduce; -let everyU = Belt_internalAVLtree.everyU; +let everyU = Belt_internalAVLtree.every; let every = Belt_internalAVLtree.every; -let someU = Belt_internalAVLtree.someU; +let someU = Belt_internalAVLtree.some; let some = Belt_internalAVLtree.some; @@ -228,25 +222,27 @@ let getExn = Belt_internalMapInt.getExn; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; -let mergeU = Belt_internalMapInt.mergeU; +let updateU = update; + +let mergeU = Belt_internalMapInt.merge; let merge = Belt_internalMapInt.merge; -let keepU = Belt_internalAVLtree.keepSharedU; +let keepU = Belt_internalAVLtree.keepShared; let keep = Belt_internalAVLtree.keepShared; -let partitionU = Belt_internalAVLtree.partitionSharedU; +let partitionU = Belt_internalAVLtree.partitionShared; let partition = Belt_internalAVLtree.partitionShared; let split = Belt_internalMapInt.split; -let mapU = Belt_internalAVLtree.mapU; +let mapU = Belt_internalAVLtree.map; let map = Belt_internalAVLtree.map; -let mapWithKeyU = Belt_internalAVLtree.mapWithKeyU; +let mapWithKeyU = Belt_internalAVLtree.mapWithKey; let mapWithKey = Belt_internalAVLtree.mapWithKey; diff --git a/belt/src/belt_MapInt.res b/belt/src/belt_MapInt.res index db0bcd4..9b06803 100644 --- a/belt/src/belt_MapInt.res +++ b/belt/src/belt_MapInt.res @@ -18,21 +18,14 @@ let minimum = N.minimum let minUndefined = N.minUndefined let maximum = N.maximum let maxUndefined = N.maxUndefined -let forEachU = N.forEachU +let findFirstBy = N.findFirstBy let forEach = N.forEach -let mapU = N.mapU let map = N.map -let mapWithKeyU = N.mapWithKeyU let mapWithKey = N.mapWithKey -let reduceU = N.reduceU let reduce = N.reduce -let everyU = N.everyU let every = N.every -let someU = N.someU let some = N.some -let keepU = N.keepSharedU let keep = N.keepShared -let partitionU = N.partitionSharedU let partition = N.partitionShared let size = N.size let toList = N.toList @@ -58,7 +51,7 @@ let rec set = (t, newK: key, newD: _) => } } -let rec updateU = (t, x: key, f) => +let rec update = (t, x: key, f) => switch t { | None => switch f(None) { @@ -84,14 +77,14 @@ let rec updateU = (t, x: key, f) => } else { let {N.left: l, right: r, value: v} = n if x < k { - let ll = updateU(l, x, f) + let ll = update(l, x, f) if l === ll { t } else { N.bal(ll, k, v, r) } } else { - let rr = updateU(r, x, f) + let rr = update(r, x, f) if r === rr { t } else { @@ -101,8 +94,6 @@ let rec updateU = (t, x: key, f) => } } -let update = (t, x, f) => updateU(t, x, a => f(a)) - let rec removeAux = (n, x: key) => { let {N.left: l, key: v, right: r} = n if x == v { @@ -162,9 +153,6 @@ let removeMany = (t, keys) => { } } -let findFirstByU = N.findFirstByU -let findFirstBy = N.findFirstBy - let mergeMany = (h, arr) => { let len = A.length(arr) let v = ref(h) @@ -178,15 +166,26 @@ let mergeMany = (h, arr) => { /* let mergeArray = mergeMany */ let has = I.has -let cmpU = I.cmpU let cmp = I.cmp -let eqU = I.eqU let eq = I.eq let get = I.get let getUndefined = I.getUndefined let getWithDefault = I.getWithDefault let getExn = I.getExn let split = I.split -let mergeU = I.mergeU let merge = I.merge let fromArray = I.fromArray + +let cmpU = cmp +let eqU = eq +let everyU = every +let findFirstByU = findFirstBy +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithKeyU = mapWithKey +let mergeU = merge +let partitionU = partition +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MapInt.resi b/belt/src/belt_MapInt.resi index c394e9b..34e1fb8 100644 --- a/belt/src/belt_MapInt.resi +++ b/belt/src/belt_MapInt.resi @@ -9,9 +9,11 @@ let isEmpty: t<'v> => bool let has: (t<'v>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'v>, t<'v>, ('v, 'v) => int) => int let cmp: (t<'v>, t<'v>, ('v, 'v) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'v>, t<'v>, ('v, 'v) => bool) => bool /** @@ -21,6 +23,7 @@ equal data. */ let eq: (t<'v>, t<'v>, ('v, 'v) => bool) => bool +@deprecated("Use `findFirstBy` instead") let findFirstByU: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> /** @@ -34,6 +37,7 @@ findFirstBy(s0, (k, v) => k == 4) == option((4, "4")) */ let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> +@deprecated("Use `forEach` instead") let forEachU: (t<'v>, (key, 'v) => unit) => unit /** @@ -44,6 +48,7 @@ order with respect to the ordering over the type of the keys. */ let forEach: (t<'v>, (key, 'v) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 /** @@ -53,6 +58,7 @@ where `k1 ... kN` are the keys of all bindings in `m` */ let reduce: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 +@deprecated("Use `every` instead") let everyU: (t<'v>, (key, 'v) => bool) => bool /** @@ -60,6 +66,7 @@ let everyU: (t<'v>, (key, 'v) => bool) => bool Order unspecified */ let every: (t<'v>, (key, 'v) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'v>, (key, 'v) => bool) => bool /** @@ -122,9 +129,11 @@ in `m`, its previous binding disappears. */ let set: (t<'v>, key, 'v) => t<'v> +@deprecated("Use `update` instead") let updateU: (t<'v>, key, option<'v> => option<'v>) => t<'v> let update: (t<'v>, key, option<'v> => option<'v>) => t<'v> +@deprecated("Use `merge` instead") let mergeU: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c> /** @@ -136,6 +145,7 @@ let merge: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c let mergeMany: (t<'v>, array<(key, 'v)>) => t<'v> +@deprecated("Use `keep` instead") let keepU: (t<'v>, (key, 'v) => bool) => t<'v> /** @@ -144,6 +154,7 @@ let keepU: (t<'v>, (key, 'v) => bool) => t<'v> */ let keep: (t<'v>, (key, 'v) => bool) => t<'v> +@deprecated("Use `partition` instead") let partitionU: (t<'v>, (key, 'v) => bool) => (t<'v>, t<'v>) /** @@ -161,6 +172,7 @@ contains no binding for `x`, or `Some(v)` if `m` binds `v` to `x`. */ let split: (key, t<'v>) => (t<'v>, option<'v>, t<'v>) +@deprecated("Use `map` instead") let mapU: (t<'v>, 'v => 'v2) => t<'v2> /** @@ -171,5 +183,6 @@ ordering over the type of the keys. */ let map: (t<'v>, 'v => 'v2) => t<'v2> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'v>, (key, 'v) => 'v2) => t<'v2> let mapWithKey: (t<'v>, (key, 'v) => 'v2) => t<'v2> diff --git a/belt/src/belt_MapString.js b/belt/src/belt_MapString.js index bda4b5b..edd1b63 100644 --- a/belt/src/belt_MapString.js +++ b/belt/src/belt_MapString.js @@ -20,7 +20,7 @@ function set(t, newK, newD) { } } -function updateU(t, x, f) { +function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { @@ -49,14 +49,14 @@ function updateU(t, x, f) { let l$1 = t.l; let r$2 = t.r; if (x < k) { - let ll = updateU(l$1, x, f); + let ll = update(l$1, x, f); if (l$1 === ll) { return t; } else { return Belt_internalAVLtree.bal(ll, k, v, r$2); } } - let rr = updateU(r$2, x, f); + let rr = update(r$2, x, f); if (r$2 === rr) { return t; } else { @@ -71,12 +71,6 @@ function updateU(t, x, f) { } } -function update(t, x, f) { - return updateU(t, x, (function (a) { - return f(a); - })); -} - function removeAux(n, x) { let v = n.k; let l = n.l; @@ -162,31 +156,31 @@ let isEmpty = Belt_internalAVLtree.isEmpty; let has = Belt_internalMapString.has; -let cmpU = Belt_internalMapString.cmpU; +let cmpU = Belt_internalMapString.cmp; let cmp = Belt_internalMapString.cmp; -let eqU = Belt_internalMapString.eqU; +let eqU = Belt_internalMapString.eq; let eq = Belt_internalMapString.eq; -let findFirstByU = Belt_internalAVLtree.findFirstByU; +let findFirstByU = Belt_internalAVLtree.findFirstBy; let findFirstBy = Belt_internalAVLtree.findFirstBy; -let forEachU = Belt_internalAVLtree.forEachU; +let forEachU = Belt_internalAVLtree.forEach; let forEach = Belt_internalAVLtree.forEach; -let reduceU = Belt_internalAVLtree.reduceU; +let reduceU = Belt_internalAVLtree.reduce; let reduce = Belt_internalAVLtree.reduce; -let everyU = Belt_internalAVLtree.everyU; +let everyU = Belt_internalAVLtree.every; let every = Belt_internalAVLtree.every; -let someU = Belt_internalAVLtree.someU; +let someU = Belt_internalAVLtree.some; let some = Belt_internalAVLtree.some; @@ -228,25 +222,27 @@ let getExn = Belt_internalMapString.getExn; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; -let mergeU = Belt_internalMapString.mergeU; +let updateU = update; + +let mergeU = Belt_internalMapString.merge; let merge = Belt_internalMapString.merge; -let keepU = Belt_internalAVLtree.keepSharedU; +let keepU = Belt_internalAVLtree.keepShared; let keep = Belt_internalAVLtree.keepShared; -let partitionU = Belt_internalAVLtree.partitionSharedU; +let partitionU = Belt_internalAVLtree.partitionShared; let partition = Belt_internalAVLtree.partitionShared; let split = Belt_internalMapString.split; -let mapU = Belt_internalAVLtree.mapU; +let mapU = Belt_internalAVLtree.map; let map = Belt_internalAVLtree.map; -let mapWithKeyU = Belt_internalAVLtree.mapWithKeyU; +let mapWithKeyU = Belt_internalAVLtree.mapWithKey; let mapWithKey = Belt_internalAVLtree.mapWithKey; diff --git a/belt/src/belt_MapString.res b/belt/src/belt_MapString.res index 1ff0d91..b0841df 100644 --- a/belt/src/belt_MapString.res +++ b/belt/src/belt_MapString.res @@ -18,21 +18,14 @@ let minimum = N.minimum let minUndefined = N.minUndefined let maximum = N.maximum let maxUndefined = N.maxUndefined -let forEachU = N.forEachU +let findFirstBy = N.findFirstBy let forEach = N.forEach -let mapU = N.mapU let map = N.map -let mapWithKeyU = N.mapWithKeyU let mapWithKey = N.mapWithKey -let reduceU = N.reduceU let reduce = N.reduce -let everyU = N.everyU let every = N.every -let someU = N.someU let some = N.some -let keepU = N.keepSharedU let keep = N.keepShared -let partitionU = N.partitionSharedU let partition = N.partitionShared let size = N.size let toList = N.toList @@ -58,7 +51,7 @@ let rec set = (t, newK: key, newD: _) => } } -let rec updateU = (t, x: key, f) => +let rec update = (t, x: key, f) => switch t { | None => switch f(None) { @@ -84,14 +77,14 @@ let rec updateU = (t, x: key, f) => } else { let {N.left: l, right: r, value: v} = n if x < k { - let ll = updateU(l, x, f) + let ll = update(l, x, f) if l === ll { t } else { N.bal(ll, k, v, r) } } else { - let rr = updateU(r, x, f) + let rr = update(r, x, f) if r === rr { t } else { @@ -101,8 +94,6 @@ let rec updateU = (t, x: key, f) => } } -let update = (t, x, f) => updateU(t, x, a => f(a)) - let rec removeAux = (n, x: key) => { let {N.left: l, key: v, right: r} = n if x == v { @@ -162,9 +153,6 @@ let removeMany = (t, keys) => { } } -let findFirstByU = N.findFirstByU -let findFirstBy = N.findFirstBy - let mergeMany = (h, arr) => { let len = A.length(arr) let v = ref(h) @@ -178,15 +166,26 @@ let mergeMany = (h, arr) => { /* let mergeArray = mergeMany */ let has = I.has -let cmpU = I.cmpU let cmp = I.cmp -let eqU = I.eqU let eq = I.eq let get = I.get let getUndefined = I.getUndefined let getWithDefault = I.getWithDefault let getExn = I.getExn let split = I.split -let mergeU = I.mergeU let merge = I.merge let fromArray = I.fromArray + +let cmpU = cmp +let eqU = eq +let everyU = every +let findFirstByU = findFirstBy +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithKeyU = mapWithKey +let mergeU = merge +let partitionU = partition +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MapString.resi b/belt/src/belt_MapString.resi index 145f38c..3a66652 100644 --- a/belt/src/belt_MapString.resi +++ b/belt/src/belt_MapString.resi @@ -9,9 +9,11 @@ let isEmpty: t<'v> => bool let has: (t<'v>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'v>, t<'v>, ('v, 'v) => int) => int let cmp: (t<'v>, t<'v>, ('v, 'v) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'v>, t<'v>, ('v, 'v) => bool) => bool /** @@ -21,6 +23,7 @@ equal data. */ let eq: (t<'v>, t<'v>, ('v, 'v) => bool) => bool +@deprecated("Use `findFirstBy` instead") let findFirstByU: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> /** @@ -34,6 +37,7 @@ findFirstBy(s0, (k, v) => k == 4) == option((4, "4")) */ let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> +@deprecated("Use `forEach` instead") let forEachU: (t<'v>, (key, 'v) => unit) => unit /** @@ -44,6 +48,7 @@ order with respect to the ordering over the type of the keys. */ let forEach: (t<'v>, (key, 'v) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 /** @@ -53,6 +58,7 @@ where `k1 ... kN` are the keys of all bindings in `m` */ let reduce: (t<'v>, 'v2, ('v2, key, 'v) => 'v2) => 'v2 +@deprecated("Use `every` instead") let everyU: (t<'v>, (key, 'v) => bool) => bool /** @@ -60,6 +66,7 @@ let everyU: (t<'v>, (key, 'v) => bool) => bool Order unspecified */ let every: (t<'v>, (key, 'v) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'v>, (key, 'v) => bool) => bool /** @@ -122,9 +129,11 @@ in `m`, its previous binding disappears. */ let set: (t<'v>, key, 'v) => t<'v> +@deprecated("Use `update` instead") let updateU: (t<'v>, key, option<'v> => option<'v>) => t<'v> let update: (t<'v>, key, option<'v> => option<'v>) => t<'v> +@deprecated("Use `merge` instead") let mergeU: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c> /** @@ -136,6 +145,7 @@ let merge: (t<'v>, t<'v2>, (key, option<'v>, option<'v2>) => option<'c>) => t<'c let mergeMany: (t<'v>, array<(key, 'v)>) => t<'v> +@deprecated("Use `keep` instead") let keepU: (t<'v>, (key, 'v) => bool) => t<'v> /** @@ -144,6 +154,7 @@ let keepU: (t<'v>, (key, 'v) => bool) => t<'v> */ let keep: (t<'v>, (key, 'v) => bool) => t<'v> +@deprecated("Use `partition` instead") let partitionU: (t<'v>, (key, 'v) => bool) => (t<'v>, t<'v>) /** @@ -161,6 +172,7 @@ contains no binding for `x`, or `Some(v)` if `m` binds `v` to `x`. */ let split: (key, t<'v>) => (t<'v>, option<'v>, t<'v>) +@deprecated("Use `map` instead") let mapU: (t<'v>, 'v => 'v2) => t<'v2> /** @@ -171,5 +183,6 @@ ordering over the type of the keys. */ let map: (t<'v>, 'v => 'v2) => t<'v2> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'v>, (key, 'v) => 'v2) => t<'v2> let mapWithKey: (t<'v>, (key, 'v) => 'v2) => t<'v2> diff --git a/belt/src/belt_MutableMap.js b/belt/src/belt_MutableMap.js index cf254be..8e6cccc 100644 --- a/belt/src/belt_MutableMap.js +++ b/belt/src/belt_MutableMap.js @@ -125,7 +125,7 @@ function updateDone(t, x, f, cmp) { } } -function updateU(t, x, f) { +function update(t, x, f) { let oldRoot = t.data; let newRoot = updateDone(oldRoot, x, f, t.cmp); if (newRoot !== oldRoot) { @@ -135,12 +135,6 @@ function updateU(t, x, f) { } -function update(t, x, f) { - updateU(t, x, (function (a) { - return f(a); - })); -} - function make(id) { return { cmp: id.cmp, @@ -188,44 +182,20 @@ function maxUndefined(m) { return Belt_internalAVLtree.maxUndefined(m.data); } -function forEachU(d, f) { - Belt_internalAVLtree.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLtree.forEachU(d.data, (function (a, b) { - f(a, b); - })); -} - -function reduceU(d, acc, cb) { - return Belt_internalAVLtree.reduceU(d.data, acc, cb); + Belt_internalAVLtree.forEach(d.data, f); } function reduce(d, acc, cb) { - return reduceU(d, acc, (function (a, b, c) { - return cb(a, b, c); - })); -} - -function everyU(d, p) { - return Belt_internalAVLtree.everyU(d.data, p); + return Belt_internalAVLtree.reduce(d.data, acc, cb); } function every(d, p) { - return Belt_internalAVLtree.everyU(d.data, (function (a, b) { - return p(a, b); - })); -} - -function someU(d, p) { - return Belt_internalAVLtree.someU(d.data, p); + return Belt_internalAVLtree.every(d.data, p); } function some(d, p) { - return Belt_internalAVLtree.someU(d.data, (function (a, b) { - return p(a, b); - })); + return Belt_internalAVLtree.some(d.data, p); } function size(d) { @@ -252,52 +222,28 @@ function checkInvariantInternal(d) { Belt_internalAVLtree.checkInvariantInternal(d.data); } -function cmpU(m1, m2, cmp) { - return Belt_internalAVLtree.cmpU(m1.data, m2.data, m1.cmp, cmp); -} - function cmp(m1, m2, cmp$1) { - return cmpU(m1, m2, (function (a, b) { - return cmp$1(a, b); - })); -} - -function eqU(m1, m2, cmp) { - return Belt_internalAVLtree.eqU(m1.data, m2.data, m1.cmp, cmp); + return Belt_internalAVLtree.cmp(m1.data, m2.data, m1.cmp, cmp$1); } function eq(m1, m2, cmp) { - return eqU(m1, m2, (function (a, b) { - return cmp(a, b); - })); + return Belt_internalAVLtree.eq(m1.data, m2.data, m1.cmp, cmp); } -function mapU(m, f) { +function map(m, f) { return { cmp: m.cmp, - data: Belt_internalAVLtree.mapU(m.data, f) + data: Belt_internalAVLtree.map(m.data, f) }; } -function map(m, f) { - return mapU(m, (function (a) { - return f(a); - })); -} - -function mapWithKeyU(m, f) { +function mapWithKey(m, f) { return { cmp: m.cmp, - data: Belt_internalAVLtree.mapWithKeyU(m.data, f) + data: Belt_internalAVLtree.mapWithKey(m.data, f) }; } -function mapWithKey(m, f) { - return mapWithKeyU(m, (function (a, b) { - return f(a, b); - })); -} - function get(m, x) { return Belt_internalAVLtree.get(m.data, x, m.cmp); } @@ -359,6 +305,24 @@ let Int; let $$String; +let cmpU = cmp; + +let eqU = eq; + +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let updateU = update; + +let mapU = map; + +let mapWithKeyU = mapWithKey; + export { Int, $$String, diff --git a/belt/src/belt_MutableMap.res b/belt/src/belt_MutableMap.res index 3409a82..b27c679 100644 --- a/belt/src/belt_MutableMap.res +++ b/belt/src/belt_MutableMap.res @@ -136,14 +136,13 @@ let rec updateDone = (t, x, f, ~cmp) => Some(N.balMutate(nt)) } } -let updateU = (t, x, f) => { +let update = (t, x, f) => { let oldRoot = t.data let newRoot = updateDone(oldRoot, x, f, ~cmp=t.cmp) if newRoot !== oldRoot { t.data = newRoot } } -let update = (t, x, f) => updateU(t, x, a => f(a)) let make = (type key identity, ~id: id) => { module M = unpack(id) @@ -163,14 +162,10 @@ let minUndefined = m => N.minUndefined(m.data) let maximum = m => N.maximum(m.data) let maxUndefined = m => N.maxUndefined(m.data) -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, (a, b) => f(a, b)) -let reduceU = (d, acc, cb) => N.reduceU(d.data, acc, cb) -let reduce = (d, acc, cb) => reduceU(d, acc, (a, b, c) => cb(a, b, c)) -let everyU = (d, p) => N.everyU(d.data, p) -let every = (d, p) => everyU(d, (a, b) => p(a, b)) -let someU = (d, p) => N.someU(d.data, p) -let some = (d, p) => someU(d, (a, b) => p(a, b)) +let forEach = (d, f) => N.forEach(d.data, f) +let reduce = (d, acc, cb) => N.reduce(d.data, acc, cb) +let every = (d, p) => N.every(d.data, p) +let some = (d, p) => N.some(d.data, p) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -183,16 +178,12 @@ let valuesToArray = d => N.valuesToArray(d.data) let checkInvariantInternal = d => N.checkInvariantInternal(d.data) -let cmpU = (m1, m2, cmp) => N.cmpU(~kcmp=m1.cmp, ~vcmp=cmp, m1.data, m2.data) -let cmp = (m1, m2, cmp) => cmpU(m1, m2, (a, b) => cmp(a, b)) +let cmp = (m1, m2, cmp) => N.cmp(~kcmp=m1.cmp, ~vcmp=cmp, m1.data, m2.data) -let eqU = (m1, m2, cmp) => N.eqU(~kcmp=m1.cmp, ~veq=cmp, m1.data, m2.data) -let eq = (m1, m2, cmp) => eqU(m1, m2, (a, b) => cmp(a, b)) +let eq = (m1, m2, cmp) => N.eq(~kcmp=m1.cmp, ~veq=cmp, m1.data, m2.data) -let mapU = (m, f) => {cmp: m.cmp, data: N.mapU(m.data, f)} -let map = (m, f) => mapU(m, a => f(a)) -let mapWithKeyU = (m, f) => {cmp: m.cmp, data: N.mapWithKeyU(m.data, f)} -let mapWithKey = (m, f) => mapWithKeyU(m, (a, b) => f(a, b)) +let map = (m, f) => {cmp: m.cmp, data: N.map(m.data, f)} +let mapWithKey = (m, f) => {cmp: m.cmp, data: N.mapWithKey(m.data, f)} let get = (m, x) => N.get(~cmp=m.cmp, m.data, x) let getUndefined = (m, x) => N.getUndefined(~cmp=m.cmp, m.data, x) @@ -233,3 +224,13 @@ let mergeMany = (d, xs) => { d.data = newRoot } } + +let cmpU = cmp +let eqU = eq +let everyU = every +let forEachU = forEach +let mapU = map +let mapWithKeyU = mapWithKey +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MutableMap.resi b/belt/src/belt_MutableMap.resi index e4000cc..5a36174 100644 --- a/belt/src/belt_MutableMap.resi +++ b/belt/src/belt_MutableMap.resi @@ -49,6 +49,7 @@ let clear: t<_> => unit let isEmpty: t<_> => bool let has: (t<'k, _, _>, 'k) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ('a, 'a) => int) => int /** `cmp(m1, m2, cmp)` First compare by size, if size is the same, compare by @@ -56,6 +57,7 @@ key, value pair. */ let cmp: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ('a, 'a) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ('a, 'a) => bool) => bool /** `eq(m1, m2, eqf)` tests whether the maps `m1` and `m2` are equal, that is, @@ -64,6 +66,7 @@ equality predicate used to compare the data associated with the keys. */ let eq: (t<'k, 'a, 'id>, t<'k, 'a, 'id>, ('a, 'a) => bool) => bool +@deprecated("Use `forEach` instead") let forEachU: (t<'k, 'a, 'id>, ('k, 'a) => unit) => unit /** `forEach(m, f)` applies f to all bindings in map `m`. `f` receives the `'k` @@ -73,6 +76,7 @@ over the type of the keys. */ let forEach: (t<'k, 'a, 'id>, ('k, 'a) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'k, 'a, 'id>, 'b, ('b, 'k, 'a) => 'b) => 'b /** `reduce(m, a, f), computes`(f(kN, dN) ... (f(k1, d1, a))...)`, where`k1 ... @@ -81,12 +85,14 @@ are the associated data. */ let reduce: (t<'k, 'a, 'id>, 'b, ('b, 'k, 'a) => 'b) => 'b +@deprecated("Use `every` instead") let everyU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool /** `every(m, p)` checks if all the bindings of the map satisfy the predicate `p`. */ let every: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool /** `some(m, p)` checks if at least one binding of the map satisfy the predicate `p`. @@ -130,11 +136,13 @@ let removeMany: (t<'k, 'a, 'id>, array<'k>) => unit /** `set(m, x, y)` do the in-place modification */ let set: (t<'k, 'a, 'id>, 'k, 'a) => unit +@deprecated("Use `update` instead") let updateU: (t<'k, 'a, 'id>, 'k, option<'a> => option<'a>) => unit let update: (t<'k, 'a, 'id>, 'k, option<'a> => option<'a>) => unit let mergeMany: (t<'k, 'a, 'id>, array<('k, 'a)>) => unit +@deprecated("Use `map` instead") let mapU: (t<'k, 'a, 'id>, 'a => 'b) => t<'k, 'b, 'id> /** `map(m, f)` returns a map with same domain as `m`, where the associated @@ -144,5 +152,6 @@ order with respect to the ordering over the type of the keys. */ let map: (t<'k, 'a, 'id>, 'a => 'b) => t<'k, 'b, 'id> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id> let mapWithKey: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id> diff --git a/belt/src/belt_MutableMapInt.js b/belt/src/belt_MutableMapInt.js index dc7fba8..abd5b46 100644 --- a/belt/src/belt_MutableMapInt.js +++ b/belt/src/belt_MutableMapInt.js @@ -60,68 +60,32 @@ function set(m, k, v) { } -function forEachU(d, f) { - Belt_internalAVLtree.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLtree.forEachU(d.data, (function (a, b) { - f(a, b); - })); -} - -function mapU(d, f) { - return { - data: Belt_internalAVLtree.mapU(d.data, f) - }; + Belt_internalAVLtree.forEach(d.data, f); } function map(d, f) { - return mapU(d, (function (a) { - return f(a); - })); -} - -function mapWithKeyU(d, f) { return { - data: Belt_internalAVLtree.mapWithKeyU(d.data, f) + data: Belt_internalAVLtree.map(d.data, f) }; } function mapWithKey(d, f) { - return mapWithKeyU(d, (function (a, b) { - return f(a, b); - })); -} - -function reduceU(d, acc, f) { - return Belt_internalAVLtree.reduceU(d.data, acc, f); + return { + data: Belt_internalAVLtree.mapWithKey(d.data, f) + }; } function reduce(d, acc, f) { - return reduceU(d, acc, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(d, f) { - return Belt_internalAVLtree.everyU(d.data, f); + return Belt_internalAVLtree.reduce(d.data, acc, f); } function every(d, f) { - return Belt_internalAVLtree.everyU(d.data, (function (a, b) { - return f(a, b); - })); -} - -function someU(d, f) { - return Belt_internalAVLtree.someU(d.data, f); + return Belt_internalAVLtree.every(d.data, f); } function some(d, f) { - return Belt_internalAVLtree.someU(d.data, (function (a, b) { - return f(a, b); - })); + return Belt_internalAVLtree.some(d.data, f); } function size(d) { @@ -239,7 +203,7 @@ function updateDone(t, x, f) { } } -function updateU(t, x, f) { +function update(t, x, f) { let oldRoot = t.data; let newRoot = updateDone(oldRoot, x, f); if (newRoot !== oldRoot) { @@ -249,12 +213,6 @@ function updateU(t, x, f) { } -function update(t, x, f) { - updateU(t, x, (function (a) { - return f(a); - })); -} - function removeArrayMutateAux(_t, xs, _i, len) { while(true) { let i = _i; @@ -293,24 +251,12 @@ function fromArray(xs) { }; } -function cmpU(d0, d1, f) { - return Belt_internalMapInt.cmpU(d0.data, d1.data, f); -} - function cmp(d0, d1, f) { - return cmpU(d0, d1, (function (a, b) { - return f(a, b); - })); -} - -function eqU(d0, d1, f) { - return Belt_internalMapInt.eqU(d0.data, d1.data, f); + return Belt_internalMapInt.cmp(d0.data, d1.data, f); } function eq(d0, d1, f) { - return eqU(d0, d1, (function (a, b) { - return f(a, b); - })); + return Belt_internalMapInt.eq(d0.data, d1.data, f); } function get(d, x) { @@ -329,6 +275,24 @@ function getExn(d, x) { return Belt_internalMapInt.getExn(d.data, x); } +let cmpU = cmp; + +let eqU = eq; + +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let updateU = update; + +let mapU = map; + +let mapWithKeyU = mapWithKey; + export { make, clear, diff --git a/belt/src/belt_MutableMapInt.res b/belt/src/belt_MutableMapInt.res index f10b06a..31f145d 100644 --- a/belt/src/belt_MutableMapInt.res +++ b/belt/src/belt_MutableMapInt.res @@ -28,18 +28,12 @@ let set = (m: t<_>, k, v) => { } } -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, (a, b) => f(a, b)) -let mapU = (d, f) => {data: N.mapU(d.data, f)} -let map = (d, f) => mapU(d, a => f(a)) -let mapWithKeyU = (d, f) => {data: N.mapWithKeyU(d.data, f)} -let mapWithKey = (d, f) => mapWithKeyU(d, (a, b) => f(a, b)) -let reduceU = (d, acc, f) => N.reduceU(d.data, acc, f) -let reduce = (d, acc, f) => reduceU(d, acc, (a, b, c) => f(a, b, c)) -let everyU = (d, f) => N.everyU(d.data, f) -let every = (d, f) => everyU(d, (a, b) => f(a, b)) -let someU = (d, f) => N.someU(d.data, f) -let some = (d, f) => someU(d, (a, b) => f(a, b)) +let forEach = (d, f) => N.forEach(d.data, f) +let map = (d, f) => {data: N.map(d.data, f)} +let mapWithKey = (d, f) => {data: N.mapWithKey(d.data, f)} +let reduce = (d, acc, f) => N.reduce(d.data, acc, f) +let every = (d, f) => N.every(d.data, f) +let some = (d, f) => N.some(d.data, f) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -126,14 +120,14 @@ let rec updateDone = (t, x: key, f) => } } -let updateU = (t, x, f) => { +let update = (t, x, f) => { let oldRoot = t.data let newRoot = updateDone(oldRoot, x, f) if newRoot !== oldRoot { t.data = newRoot } } -let update = (t, x, f) => updateU(t, x, a => f(a)) + let rec removeArrayMutateAux = (t, xs, i, len) => if i < len { let ele = A.getUnsafe(xs, i) @@ -164,13 +158,21 @@ let removeMany = (d: t<_>, xs) => { let fromArray = xs => {data: I.fromArray(xs)} -let cmpU = (d0, d1, f) => I.cmpU(d0.data, d1.data, f) -let cmp = (d0, d1, f) => cmpU(d0, d1, (a, b) => f(a, b)) +let cmp = (d0, d1, f) => I.cmp(d0.data, d1.data, f) -let eqU = (d0, d1, f) => I.eqU(d0.data, d1.data, f) -let eq = (d0, d1, f) => eqU(d0, d1, (a, b) => f(a, b)) +let eq = (d0, d1, f) => I.eq(d0.data, d1.data, f) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) let getWithDefault = (d, x, def) => I.getWithDefault(d.data, x, def) let getExn = (d, x) => I.getExn(d.data, x) + +let cmpU = cmp +let eqU = eq +let everyU = every +let forEachU = forEach +let mapU = map +let mapWithKeyU = mapWithKey +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MutableMapInt.resi b/belt/src/belt_MutableMapInt.resi index 1bd09b2..7319d0f 100644 --- a/belt/src/belt_MutableMapInt.resi +++ b/belt/src/belt_MutableMapInt.resi @@ -32,6 +32,7 @@ let isEmpty: t<'a> => bool let has: (t<'a>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'a>, t<'a>, ('a, 'a) => int) => int /** @@ -40,11 +41,13 @@ value pair */ let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** `eq(m1, m2, cmp)` */ let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, (key, 'a) => unit) => unit /** @@ -53,6 +56,7 @@ first argument, and the associated value as second argument. The application order of `f` is in increasing order. */ let forEach: (t<'a>, (key, 'a) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b /** @@ -61,6 +65,7 @@ the keys of all bindings in `m` (in increasing order), and `d1 ... dN` are the associated data. */ let reduce: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b +@deprecated("Use `every` instead") let everyU: (t<'a>, (key, 'a) => bool) => bool /** @@ -69,6 +74,7 @@ The application order of `p` is unspecified. */ let every: (t<'a>, (key, 'a) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'a>, (key, 'a) => bool) => bool /** @@ -121,9 +127,11 @@ already bound in `m`, its previous binding disappears. */ let set: (t<'a>, key, 'a) => unit +@deprecated("Use `update` instead") let updateU: (t<'a>, key, option<'a> => option<'a>) => unit let update: (t<'a>, key, option<'a> => option<'a>) => unit +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => t<'b> /** @@ -133,5 +141,6 @@ to `a`. The bindings are passed to `f` in increasing order with respect to the ordering over the type of the keys. */ let map: (t<'a>, 'a => 'b) => t<'b> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'a>, (key, 'a) => 'b) => t<'b> let mapWithKey: (t<'a>, (key, 'a) => 'b) => t<'b> diff --git a/belt/src/belt_MutableMapString.js b/belt/src/belt_MutableMapString.js index 4d330f9..2af1002 100644 --- a/belt/src/belt_MutableMapString.js +++ b/belt/src/belt_MutableMapString.js @@ -60,68 +60,32 @@ function set(m, k, v) { } -function forEachU(d, f) { - Belt_internalAVLtree.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLtree.forEachU(d.data, (function (a, b) { - f(a, b); - })); -} - -function mapU(d, f) { - return { - data: Belt_internalAVLtree.mapU(d.data, f) - }; + Belt_internalAVLtree.forEach(d.data, f); } function map(d, f) { - return mapU(d, (function (a) { - return f(a); - })); -} - -function mapWithKeyU(d, f) { return { - data: Belt_internalAVLtree.mapWithKeyU(d.data, f) + data: Belt_internalAVLtree.map(d.data, f) }; } function mapWithKey(d, f) { - return mapWithKeyU(d, (function (a, b) { - return f(a, b); - })); -} - -function reduceU(d, acc, f) { - return Belt_internalAVLtree.reduceU(d.data, acc, f); + return { + data: Belt_internalAVLtree.mapWithKey(d.data, f) + }; } function reduce(d, acc, f) { - return reduceU(d, acc, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(d, f) { - return Belt_internalAVLtree.everyU(d.data, f); + return Belt_internalAVLtree.reduce(d.data, acc, f); } function every(d, f) { - return Belt_internalAVLtree.everyU(d.data, (function (a, b) { - return f(a, b); - })); -} - -function someU(d, f) { - return Belt_internalAVLtree.someU(d.data, f); + return Belt_internalAVLtree.every(d.data, f); } function some(d, f) { - return Belt_internalAVLtree.someU(d.data, (function (a, b) { - return f(a, b); - })); + return Belt_internalAVLtree.some(d.data, f); } function size(d) { @@ -239,7 +203,7 @@ function updateDone(t, x, f) { } } -function updateU(t, x, f) { +function update(t, x, f) { let oldRoot = t.data; let newRoot = updateDone(oldRoot, x, f); if (newRoot !== oldRoot) { @@ -249,12 +213,6 @@ function updateU(t, x, f) { } -function update(t, x, f) { - updateU(t, x, (function (a) { - return f(a); - })); -} - function removeArrayMutateAux(_t, xs, _i, len) { while(true) { let i = _i; @@ -293,24 +251,12 @@ function fromArray(xs) { }; } -function cmpU(d0, d1, f) { - return Belt_internalMapString.cmpU(d0.data, d1.data, f); -} - function cmp(d0, d1, f) { - return cmpU(d0, d1, (function (a, b) { - return f(a, b); - })); -} - -function eqU(d0, d1, f) { - return Belt_internalMapString.eqU(d0.data, d1.data, f); + return Belt_internalMapString.cmp(d0.data, d1.data, f); } function eq(d0, d1, f) { - return eqU(d0, d1, (function (a, b) { - return f(a, b); - })); + return Belt_internalMapString.eq(d0.data, d1.data, f); } function get(d, x) { @@ -329,6 +275,24 @@ function getExn(d, x) { return Belt_internalMapString.getExn(d.data, x); } +let cmpU = cmp; + +let eqU = eq; + +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let updateU = update; + +let mapU = map; + +let mapWithKeyU = mapWithKey; + export { make, clear, diff --git a/belt/src/belt_MutableMapString.res b/belt/src/belt_MutableMapString.res index 7c3278f..e3010ef 100644 --- a/belt/src/belt_MutableMapString.res +++ b/belt/src/belt_MutableMapString.res @@ -28,18 +28,12 @@ let set = (m: t<_>, k, v) => { } } -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, (a, b) => f(a, b)) -let mapU = (d, f) => {data: N.mapU(d.data, f)} -let map = (d, f) => mapU(d, a => f(a)) -let mapWithKeyU = (d, f) => {data: N.mapWithKeyU(d.data, f)} -let mapWithKey = (d, f) => mapWithKeyU(d, (a, b) => f(a, b)) -let reduceU = (d, acc, f) => N.reduceU(d.data, acc, f) -let reduce = (d, acc, f) => reduceU(d, acc, (a, b, c) => f(a, b, c)) -let everyU = (d, f) => N.everyU(d.data, f) -let every = (d, f) => everyU(d, (a, b) => f(a, b)) -let someU = (d, f) => N.someU(d.data, f) -let some = (d, f) => someU(d, (a, b) => f(a, b)) +let forEach = (d, f) => N.forEach(d.data, f) +let map = (d, f) => {data: N.map(d.data, f)} +let mapWithKey = (d, f) => {data: N.mapWithKey(d.data, f)} +let reduce = (d, acc, f) => N.reduce(d.data, acc, f) +let every = (d, f) => N.every(d.data, f) +let some = (d, f) => N.some(d.data, f) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -126,14 +120,14 @@ let rec updateDone = (t, x: key, f) => } } -let updateU = (t, x, f) => { +let update = (t, x, f) => { let oldRoot = t.data let newRoot = updateDone(oldRoot, x, f) if newRoot !== oldRoot { t.data = newRoot } } -let update = (t, x, f) => updateU(t, x, a => f(a)) + let rec removeArrayMutateAux = (t, xs, i, len) => if i < len { let ele = A.getUnsafe(xs, i) @@ -164,13 +158,21 @@ let removeMany = (d: t<_>, xs) => { let fromArray = xs => {data: I.fromArray(xs)} -let cmpU = (d0, d1, f) => I.cmpU(d0.data, d1.data, f) -let cmp = (d0, d1, f) => cmpU(d0, d1, (a, b) => f(a, b)) +let cmp = (d0, d1, f) => I.cmp(d0.data, d1.data, f) -let eqU = (d0, d1, f) => I.eqU(d0.data, d1.data, f) -let eq = (d0, d1, f) => eqU(d0, d1, (a, b) => f(a, b)) +let eq = (d0, d1, f) => I.eq(d0.data, d1.data, f) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) let getWithDefault = (d, x, def) => I.getWithDefault(d.data, x, def) let getExn = (d, x) => I.getExn(d.data, x) + +let cmpU = cmp +let eqU = eq +let everyU = every +let forEachU = forEach +let mapU = map +let mapWithKeyU = mapWithKey +let reduceU = reduce +let someU = some +let updateU = update diff --git a/belt/src/belt_MutableMapString.resi b/belt/src/belt_MutableMapString.resi index 6bdec0a..4ae708d 100644 --- a/belt/src/belt_MutableMapString.resi +++ b/belt/src/belt_MutableMapString.resi @@ -32,6 +32,7 @@ let isEmpty: t<'a> => bool let has: (t<'a>, key) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'a>, t<'a>, ('a, 'a) => int) => int /** @@ -40,11 +41,13 @@ value pair */ let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int +@deprecated("Use `eq` instead") let eqU: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** `eq(m1, m2, cmp)` */ let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, (key, 'a) => unit) => unit /** @@ -53,6 +56,7 @@ first argument, and the associated value as second argument. The application order of `f` is in increasing order. */ let forEach: (t<'a>, (key, 'a) => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b /** @@ -61,6 +65,7 @@ the keys of all bindings in `m` (in increasing order), and `d1 ... dN` are the associated data. */ let reduce: (t<'a>, 'b, ('b, key, 'a) => 'b) => 'b +@deprecated("Use `every` instead") let everyU: (t<'a>, (key, 'a) => bool) => bool /** @@ -69,6 +74,7 @@ The application order of `p` is unspecified. */ let every: (t<'a>, (key, 'a) => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'a>, (key, 'a) => bool) => bool /** @@ -121,9 +127,11 @@ already bound in `m`, its previous binding disappears. */ let set: (t<'a>, key, 'a) => unit +@deprecated("Use `update` instead") let updateU: (t<'a>, key, option<'a> => option<'a>) => unit let update: (t<'a>, key, option<'a> => option<'a>) => unit +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => t<'b> /** @@ -133,5 +141,6 @@ to `a`. The bindings are passed to `f` in increasing order with respect to the ordering over the type of the keys. */ let map: (t<'a>, 'a => 'b) => t<'b> +@deprecated("Use `mapWithKey` instead") let mapWithKeyU: (t<'a>, (key, 'a) => 'b) => t<'b> let mapWithKey: (t<'a>, (key, 'a) => 'b) => t<'b> diff --git a/belt/src/belt_MutableQueue.js b/belt/src/belt_MutableQueue.js index b6002e8..54acbc9 100644 --- a/belt/src/belt_MutableQueue.js +++ b/belt/src/belt_MutableQueue.js @@ -144,7 +144,7 @@ function copy(q) { }; } -function mapU(q, f) { +function map(q, f) { let qRes = { length: q.length, first: undefined, @@ -175,12 +175,6 @@ function mapU(q, f) { }; } -function map(q, f) { - return mapU(q, (function (a) { - return f(a); - })); -} - function isEmpty(q) { return q.length === 0; } @@ -189,7 +183,7 @@ function size(q) { return q.length; } -function forEachU(q, f) { +function forEach(q, f) { let _cell = q.first; while(true) { let cell = _cell; @@ -202,13 +196,7 @@ function forEachU(q, f) { }; } -function forEach(q, f) { - forEachU(q, (function (a) { - f(a); - })); -} - -function reduceU(q, accu, f) { +function reduce(q, accu, f) { let _accu = accu; let _cell = q.first; while(true) { @@ -224,12 +212,6 @@ function reduceU(q, accu, f) { }; } -function reduce(q, accu, f) { - return reduceU(q, accu, (function (a, b) { - return f(a, b); - })); -} - function transfer(q1, q2) { if (q1.length <= 0) { return; @@ -280,6 +262,12 @@ function fromArray(arr) { return q; } +let mapU = map; + +let forEachU = forEach; + +let reduceU = reduce; + export { make, clear, diff --git a/belt/src/belt_MutableQueue.res b/belt/src/belt_MutableQueue.res index aeec077..855fc03 100644 --- a/belt/src/belt_MutableQueue.res +++ b/belt/src/belt_MutableQueue.res @@ -158,9 +158,7 @@ let rec copyMapAux = (qRes, prev, cell, f) => copyMapAux(qRes, res, x.next, f) } -let mapU = (q, f) => copyMapAux({length: q.length, first: None, last: None}, None, q.first, f) - -let map = (q, f) => mapU(q, a => f(a)) +let map = (q, f) => copyMapAux({length: q.length, first: None, last: None}, None, q.first, f) let isEmpty = q => q.length == 0 @@ -174,9 +172,7 @@ let rec iterAux = (cell, f) => iterAux(x.next, f) } -let forEachU = (q, f) => iterAux(q.first, f) - -let forEach = (q, f) => forEachU(q, a => f(a)) +let forEach = (q, f) => iterAux(q.first, f) let rec foldAux = (f, accu, cell) => switch cell { @@ -186,9 +182,7 @@ let rec foldAux = (f, accu, cell) => foldAux(f, accu, x.next) } -let reduceU = (q, accu, f) => foldAux(f, accu, q.first) - -let reduce = (q, accu, f) => reduceU(q, accu, (a, b) => f(a, b)) +let reduce = (q, accu, f) => foldAux(f, accu, q.first) let transfer = (q1, q2) => if q1.length > 0 { @@ -228,3 +222,7 @@ let fromArray = arr => { } q } + +let forEachU = forEach +let mapU = map +let reduceU = reduce diff --git a/belt/src/belt_MutableQueue.resi b/belt/src/belt_MutableQueue.resi index d388b7e..ebecc05 100644 --- a/belt/src/belt_MutableQueue.resi +++ b/belt/src/belt_MutableQueue.resi @@ -89,8 +89,10 @@ Returns the number of elements in a queue. */ let size: t<'a> => int +@deprecated("Use `map` instead") let mapU: (t<'a>, 'a => 'b) => t<'b> let map: (t<'a>, 'a => 'b) => t<'b> +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, 'a => unit) => unit /** @@ -99,6 +101,7 @@ recently entered to the most recently entered. The queue itself is unchanged. */ let forEach: (t<'a>, 'a => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'a>, 'b, ('b, 'a) => 'b) => 'b /** diff --git a/belt/src/belt_MutableSet.js b/belt/src/belt_MutableSet.js index 0f1d5c3..e7b7939 100644 --- a/belt/src/belt_MutableSet.js +++ b/belt/src/belt_MutableSet.js @@ -211,44 +211,20 @@ function maxUndefined(d) { return Belt_internalAVLset.maxUndefined(d.data); } -function forEachU(d, f) { - Belt_internalAVLset.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLset.forEachU(d.data, (function (a) { - f(a); - })); -} - -function reduceU(d, acc, cb) { - return Belt_internalAVLset.reduceU(d.data, acc, cb); + Belt_internalAVLset.forEach(d.data, f); } function reduce(d, acc, cb) { - return reduceU(d, acc, (function (a, b) { - return cb(a, b); - })); -} - -function everyU(d, p) { - return Belt_internalAVLset.everyU(d.data, p); + return Belt_internalAVLset.reduce(d.data, acc, cb); } function every(d, p) { - return Belt_internalAVLset.everyU(d.data, (function (a) { - return p(a); - })); -} - -function someU(d, p) { - return Belt_internalAVLset.someU(d.data, p); + return Belt_internalAVLset.every(d.data, p); } function some(d, p) { - return Belt_internalAVLset.someU(d.data, (function (a) { - return p(a); - })); + return Belt_internalAVLset.some(d.data, p); } function size(d) { @@ -305,7 +281,7 @@ function getExn(d, x) { function split(d, key) { let arr = Belt_internalAVLset.toArray(d.data); let cmp = d.cmp; - let i = Belt_SortArray.binarySearchByU(arr, key, cmp); + let i = Belt_SortArray.binarySearchBy(arr, key, cmp); let len = arr.length; if (i >= 0) { return [ @@ -338,22 +314,16 @@ function split(d, key) { ]; } -function keepU(d, p) { +function keep(d, p) { return { cmp: d.cmp, - data: Belt_internalAVLset.keepCopyU(d.data, p) + data: Belt_internalAVLset.keepCopy(d.data, p) }; } -function keep(d, p) { - return keepU(d, (function (a) { - return p(a); - })); -} - -function partitionU(d, p) { +function partition(d, p) { let cmp = d.cmp; - let match = Belt_internalAVLset.partitionCopyU(d.data, p); + let match = Belt_internalAVLset.partitionCopy(d.data, p); return [ { cmp: cmp, @@ -366,12 +336,6 @@ function partitionU(d, p) { ]; } -function partition(d, p) { - return partitionU(d, (function (a) { - return p(a); - })); -} - function subset(a, b) { return Belt_internalAVLset.subset(a.data, b.data, a.cmp); } @@ -405,7 +369,7 @@ function intersect(a, b) { }; } let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); - let k = Belt_SortArray.intersectU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + let k = Belt_SortArray.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); return { cmp: cmp, data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) @@ -441,7 +405,7 @@ function diff(a, b) { }; } let tmp2 = new Array(sizea); - let k = Belt_SortArray.diffU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + let k = Belt_SortArray.diff(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); return { cmp: cmp, data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) @@ -477,7 +441,7 @@ function union(a, b) { }; } let tmp2 = new Array(totalSize); - let k = Belt_SortArray.unionU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + let k = Belt_SortArray.union(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); return { cmp: cmp, data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) @@ -499,6 +463,18 @@ let Int; let $$String; +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let keepU = keep; + +let partitionU = partition; + export { Int, $$String, diff --git a/belt/src/belt_MutableSet.res b/belt/src/belt_MutableSet.res index 3cd0fb2..bc553ea 100644 --- a/belt/src/belt_MutableSet.res +++ b/belt/src/belt_MutableSet.res @@ -206,14 +206,10 @@ let minUndefined = d => N.minUndefined(d.data) let maximum = d => N.maximum(d.data) let maxUndefined = d => N.maxUndefined(d.data) -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, a => f(a)) -let reduceU = (d, acc, cb) => N.reduceU(d.data, acc, cb) -let reduce = (d, acc, cb) => reduceU(d, acc, (a, b) => cb(a, b)) -let everyU = (d, p) => N.everyU(d.data, p) -let every = (d, p) => everyU(d, a => p(a)) -let someU = (d, p) => N.someU(d.data, p) -let some = (d, p) => someU(d, a => p(a)) +let forEach = (d, f) => N.forEach(d.data, f) +let reduce = (d, acc, cb) => N.reduce(d.data, acc, cb) +let every = (d, p) => N.every(d.data, p) +let some = (d, p) => N.some(d.data, p) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -244,7 +240,7 @@ let getExn = (d, x) => N.getExn(~cmp=d.cmp, d.data, x) let split = (d, key) => { let arr = N.toArray(d.data) let cmp = d.cmp - let i = Sort.binarySearchByU(arr, key, Belt_Id.getCmpInternal(cmp)) + let i = Sort.binarySearchBy(arr, key, Belt_Id.getCmpInternal(cmp)) let len = A.length(arr) if i < 0 { let next = -i - 1 @@ -278,18 +274,14 @@ let split = (d, key) => { } } -let keepU = (d, p) => {data: N.keepCopyU(d.data, p), cmp: d.cmp} +let keep = (d, p) => {data: N.keepCopy(d.data, p), cmp: d.cmp} -let keep = (d, p) => keepU(d, a => p(a)) - -let partitionU = (d, p) => { +let partition = (d, p) => { let cmp = d.cmp - let (a, b) = N.partitionCopyU(d.data, p) + let (a, b) = N.partitionCopy(d.data, p) ({data: a, cmp}, {data: b, cmp}) } -let partition = (d, p) => partitionU(d, a => p(a)) - let subset = (a, b) => N.subset(~cmp=a.cmp, a.data, b.data) let intersect = (a, b): t<_> => { @@ -311,7 +303,7 @@ let intersect = (a, b): t<_> => { {cmp, data: None} } else { let tmp2 = A.makeUninitializedUnsafe(Pervasives.min(sizea, sizeb)) - let k = Sort.intersectU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) + let k = Sort.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) { data: N.fromSortedArrayAux(tmp2, 0, k), cmp, @@ -340,7 +332,7 @@ let diff = (a, b): t<_> => { {data: N.copy(dataa), cmp} } else { let tmp2 = A.makeUninitializedUnsafe(sizea) - let k = Sort.diffU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) + let k = Sort.diff(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) {data: N.fromSortedArrayAux(tmp2, 0, k), cmp} } } @@ -363,7 +355,7 @@ let union = (a, b) => { {data: N.fromSortedArrayAux(tmp, 0, totalSize), cmp} } else { let tmp2 = A.makeUninitializedUnsafe(totalSize) - let k = Sort.unionU(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) + let k = Sort.union(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, p) {data: N.fromSortedArrayAux(tmp2, 0, k), cmp} } } @@ -372,3 +364,10 @@ let union = (a, b) => { let has = (d, x) => N.has(~cmp=d.cmp, d.data, x) let copy = d => {data: N.copy(d.data), cmp: d.cmp} + +let everyU = every +let forEachU = forEach +let keepU = keep +let partitionU = partition +let reduceU = reduce +let someU = some diff --git a/belt/src/belt_MutableSet.resi b/belt/src/belt_MutableSet.resi index e5fd8b7..a8ab3c5 100644 --- a/belt/src/belt_MutableSet.resi +++ b/belt/src/belt_MutableSet.resi @@ -340,6 +340,7 @@ let eq: (t<'value, 'id>, t<'value, 'id>) => bool /** Same as `Belt.MutableSet.forEach` but takes uncurried functon. */ +@deprecated("Use `forEach` instead") let forEachU: (t<'value, 'id>, 'value => unit) => unit /** @@ -361,6 +362,7 @@ acc /* [6,5,3,2] */ */ let forEach: (t<'value, 'id>, 'value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a /** @@ -380,6 +382,7 @@ s0->Belt.MutableSet.reduce(list{}, (acc, element) => acc->Belt.List.add(element) */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t<'value, 'id>, 'value => bool) => bool /** @@ -401,6 +404,7 @@ s0->Belt.MutableSet.every(isEven) /* true */ */ let every: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'value, 'id>, 'value => bool) => bool /** @@ -422,6 +426,7 @@ s0->Belt.MutableSet.some(isOdd) /* true */ */ let some: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t<'value, 'id>, 'value => bool) => t<'value, 'id> /** @@ -445,6 +450,7 @@ s1->Belt.MutableSet.toArray /* [2, 4] */ */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> +@deprecated("Use `partition` instead") let partitionU: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) /** diff --git a/belt/src/belt_MutableSetInt.js b/belt/src/belt_MutableSetInt.js index 6365030..7732baa 100644 --- a/belt/src/belt_MutableSetInt.js +++ b/belt/src/belt_MutableSetInt.js @@ -208,44 +208,20 @@ function maxUndefined(d) { return Belt_internalAVLset.maxUndefined(d.data); } -function forEachU(d, f) { - Belt_internalAVLset.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLset.forEachU(d.data, (function (a) { - f(a); - })); -} - -function reduceU(d, acc, cb) { - return Belt_internalAVLset.reduceU(d.data, acc, cb); + Belt_internalAVLset.forEach(d.data, f); } function reduce(d, acc, cb) { - return reduceU(d, acc, (function (a, b) { - return cb(a, b); - })); -} - -function everyU(d, p) { - return Belt_internalAVLset.everyU(d.data, p); + return Belt_internalAVLset.reduce(d.data, acc, cb); } function every(d, p) { - return Belt_internalAVLset.everyU(d.data, (function (a) { - return p(a); - })); -} - -function someU(d, p) { - return Belt_internalAVLset.someU(d.data, p); + return Belt_internalAVLset.every(d.data, p); } function some(d, p) { - return Belt_internalAVLset.someU(d.data, (function (a) { - return p(a); - })); + return Belt_internalAVLset.some(d.data, p); } function size(d) { @@ -327,20 +303,14 @@ function split(d, key) { ]; } -function keepU(d, p) { +function keep(d, p) { return { - data: Belt_internalAVLset.keepCopyU(d.data, p) + data: Belt_internalAVLset.keepCopy(d.data, p) }; } -function keep(d, p) { - return keepU(d, (function (a) { - return p(a); - })); -} - -function partitionU(d, p) { - let match = Belt_internalAVLset.partitionCopyU(d.data, p); +function partition(d, p) { + let match = Belt_internalAVLset.partitionCopy(d.data, p); return [ { data: match[0] @@ -351,12 +321,6 @@ function partitionU(d, p) { ]; } -function partition(d, p) { - return partitionU(d, (function (a) { - return p(a); - })); -} - function subset(a, b) { return Belt_internalSetInt.subset(a.data, b.data); } @@ -464,6 +428,18 @@ function copy(d) { }; } +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let keepU = keep; + +let partitionU = partition; + export { make, fromArray, diff --git a/belt/src/belt_MutableSetInt.res b/belt/src/belt_MutableSetInt.res index 1dc90e2..3264258 100644 --- a/belt/src/belt_MutableSetInt.res +++ b/belt/src/belt_MutableSetInt.res @@ -196,25 +196,14 @@ let mergeMany = (d, arr) => d.data = addArrayMutate(d.data, arr) let make = () => {data: None} let isEmpty = d => N.isEmpty(d.data) - let minimum = d => N.minimum(d.data) - let minUndefined = d => N.minUndefined(d.data) - let maximum = d => N.maximum(d.data) - let maxUndefined = d => N.maxUndefined(d.data) - -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, a => f(a)) - -let reduceU = (d, acc, cb) => N.reduceU(d.data, acc, cb) -let reduce = (d, acc, cb) => reduceU(d, acc, (a, b) => cb(a, b)) - -let everyU = (d, p) => N.everyU(d.data, p) -let every = (d, p) => everyU(d, a => p(a)) -let someU = (d, p) => N.someU(d.data, p) -let some = (d, p) => someU(d, a => p(a)) +let forEach = (d, f) => N.forEach(d.data, f) +let reduce = (d, acc, cb) => N.reduce(d.data, acc, cb) +let every = (d, p) => N.every(d.data, p) +let some = (d, p) => N.some(d.data, p) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -255,14 +244,12 @@ let split = (d, key) => { } } -let keepU = (d, p) => {data: N.keepCopyU(d.data, p)} -let keep = (d, p) => keepU(d, a => p(a)) +let keep = (d, p) => {data: N.keepCopy(d.data, p)} -let partitionU = (d, p) => { - let (a, b) = N.partitionCopyU(d.data, p) +let partition = (d, p) => { + let (a, b) = N.partitionCopy(d.data, p) ({data: a}, {data: b}) } -let partition = (d, p) => partitionU(d, a => p(a)) let subset = (a, b) => I.subset(a.data, b.data) let intersect = (dataa, datab) => { @@ -337,3 +324,10 @@ let union = (dataa: t, datab: t): t => { let has = (d, x) => I.has(d.data, x) let copy = d => {data: N.copy(d.data)} + +let everyU = every +let forEachU = forEach +let keepU = keep +let partitionU = partition +let reduceU = reduce +let someU = some diff --git a/belt/src/belt_MutableSetInt.resi b/belt/src/belt_MutableSetInt.resi index 7078dbd..1ee0340 100644 --- a/belt/src/belt_MutableSetInt.resi +++ b/belt/src/belt_MutableSetInt.resi @@ -61,16 +61,19 @@ let subset: (t, t) => bool let cmp: (t, t) => int let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** In increasing order*/ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -78,6 +81,7 @@ let everyU: (t, value => bool) => bool Order unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -86,6 +90,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -94,6 +99,7 @@ predicate `p`. */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt/src/belt_MutableSetString.js b/belt/src/belt_MutableSetString.js index a846f80..58cc4f0 100644 --- a/belt/src/belt_MutableSetString.js +++ b/belt/src/belt_MutableSetString.js @@ -208,44 +208,20 @@ function maxUndefined(d) { return Belt_internalAVLset.maxUndefined(d.data); } -function forEachU(d, f) { - Belt_internalAVLset.forEachU(d.data, f); -} - function forEach(d, f) { - Belt_internalAVLset.forEachU(d.data, (function (a) { - f(a); - })); -} - -function reduceU(d, acc, cb) { - return Belt_internalAVLset.reduceU(d.data, acc, cb); + Belt_internalAVLset.forEach(d.data, f); } function reduce(d, acc, cb) { - return reduceU(d, acc, (function (a, b) { - return cb(a, b); - })); -} - -function everyU(d, p) { - return Belt_internalAVLset.everyU(d.data, p); + return Belt_internalAVLset.reduce(d.data, acc, cb); } function every(d, p) { - return Belt_internalAVLset.everyU(d.data, (function (a) { - return p(a); - })); -} - -function someU(d, p) { - return Belt_internalAVLset.someU(d.data, p); + return Belt_internalAVLset.every(d.data, p); } function some(d, p) { - return Belt_internalAVLset.someU(d.data, (function (a) { - return p(a); - })); + return Belt_internalAVLset.some(d.data, p); } function size(d) { @@ -327,20 +303,14 @@ function split(d, key) { ]; } -function keepU(d, p) { +function keep(d, p) { return { - data: Belt_internalAVLset.keepCopyU(d.data, p) + data: Belt_internalAVLset.keepCopy(d.data, p) }; } -function keep(d, p) { - return keepU(d, (function (a) { - return p(a); - })); -} - -function partitionU(d, p) { - let match = Belt_internalAVLset.partitionCopyU(d.data, p); +function partition(d, p) { + let match = Belt_internalAVLset.partitionCopy(d.data, p); return [ { data: match[0] @@ -351,12 +321,6 @@ function partitionU(d, p) { ]; } -function partition(d, p) { - return partitionU(d, (function (a) { - return p(a); - })); -} - function subset(a, b) { return Belt_internalSetString.subset(a.data, b.data); } @@ -464,6 +428,18 @@ function copy(d) { }; } +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let keepU = keep; + +let partitionU = partition; + export { make, fromArray, diff --git a/belt/src/belt_MutableSetString.res b/belt/src/belt_MutableSetString.res index 62f9c09..db94836 100644 --- a/belt/src/belt_MutableSetString.res +++ b/belt/src/belt_MutableSetString.res @@ -196,25 +196,14 @@ let mergeMany = (d, arr) => d.data = addArrayMutate(d.data, arr) let make = () => {data: None} let isEmpty = d => N.isEmpty(d.data) - let minimum = d => N.minimum(d.data) - let minUndefined = d => N.minUndefined(d.data) - let maximum = d => N.maximum(d.data) - let maxUndefined = d => N.maxUndefined(d.data) - -let forEachU = (d, f) => N.forEachU(d.data, f) -let forEach = (d, f) => forEachU(d, a => f(a)) - -let reduceU = (d, acc, cb) => N.reduceU(d.data, acc, cb) -let reduce = (d, acc, cb) => reduceU(d, acc, (a, b) => cb(a, b)) - -let everyU = (d, p) => N.everyU(d.data, p) -let every = (d, p) => everyU(d, a => p(a)) -let someU = (d, p) => N.someU(d.data, p) -let some = (d, p) => someU(d, a => p(a)) +let forEach = (d, f) => N.forEach(d.data, f) +let reduce = (d, acc, cb) => N.reduce(d.data, acc, cb) +let every = (d, p) => N.every(d.data, p) +let some = (d, p) => N.some(d.data, p) let size = d => N.size(d.data) let toList = d => N.toList(d.data) let toArray = d => N.toArray(d.data) @@ -255,14 +244,12 @@ let split = (d, key) => { } } -let keepU = (d, p) => {data: N.keepCopyU(d.data, p)} -let keep = (d, p) => keepU(d, a => p(a)) +let keep = (d, p) => {data: N.keepCopy(d.data, p)} -let partitionU = (d, p) => { - let (a, b) = N.partitionCopyU(d.data, p) +let partition = (d, p) => { + let (a, b) = N.partitionCopy(d.data, p) ({data: a}, {data: b}) } -let partition = (d, p) => partitionU(d, a => p(a)) let subset = (a, b) => I.subset(a.data, b.data) let intersect = (dataa, datab) => { @@ -337,3 +324,10 @@ let union = (dataa: t, datab: t): t => { let has = (d, x) => I.has(d.data, x) let copy = d => {data: N.copy(d.data)} + +let everyU = every +let forEachU = forEach +let keepU = keep +let partitionU = partition +let reduceU = reduce +let someU = some diff --git a/belt/src/belt_MutableSetString.resi b/belt/src/belt_MutableSetString.resi index 75dbe5a..4b825f2 100644 --- a/belt/src/belt_MutableSetString.resi +++ b/belt/src/belt_MutableSetString.resi @@ -61,16 +61,19 @@ let subset: (t, t) => bool let cmp: (t, t) => int let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** In increasing order*/ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -78,6 +81,7 @@ let everyU: (t, value => bool) => bool Order unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -86,6 +90,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -94,6 +99,7 @@ predicate `p`. */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt/src/belt_MutableStack.js b/belt/src/belt_MutableStack.js index 616ac3d..883c44b 100644 --- a/belt/src/belt_MutableStack.js +++ b/belt/src/belt_MutableStack.js @@ -84,7 +84,7 @@ function size(s) { } } -function forEachU(s, f) { +function forEach(s, f) { let _s = s.root; while(true) { let s$1 = _s; @@ -97,13 +97,7 @@ function forEachU(s, f) { }; } -function forEach(s, f) { - forEachU(s, (function (x) { - f(x); - })); -} - -function dynamicPopIterU(s, f) { +function dynamicPopIter(s, f) { while(true) { let match = s.root; if (match === undefined) { @@ -115,11 +109,9 @@ function dynamicPopIterU(s, f) { }; } -function dynamicPopIter(s, f) { - dynamicPopIterU(s, (function (x) { - f(x); - })); -} +let forEachU = forEach; + +let dynamicPopIterU = dynamicPopIter; export { make, diff --git a/belt/src/belt_MutableStack.res b/belt/src/belt_MutableStack.res index 07709d3..9e848f2 100644 --- a/belt/src/belt_MutableStack.res +++ b/belt/src/belt_MutableStack.res @@ -87,17 +87,16 @@ let rec iterAux = (s: opt_cell<_>, f) => iterAux(x.tail, f) } -let forEachU = (s, f) => iterAux(s.root, f) +let forEach = (s, f) => iterAux(s.root, f) -let forEach = (s, f) => forEachU(s, x => f(x)) - -let rec dynamicPopIterU = (s, f) => +let rec dynamicPopIter = (s, f) => switch s.root { | Some({tail, head}) => s.root = tail f(head) - dynamicPopIterU(s, f) /* using root, `f` may change it */ + dynamicPopIter(s, f) /* using root, `f` may change it */ | None => () } -let dynamicPopIter = (s, f) => dynamicPopIterU(s, x => f(x)) +let dynamicPopIterU = dynamicPopIter +let forEachU = forEach diff --git a/belt/src/belt_MutableStack.resi b/belt/src/belt_MutableStack.resi index 26a30cc..c2b34cd 100644 --- a/belt/src/belt_MutableStack.resi +++ b/belt/src/belt_MutableStack.resi @@ -51,8 +51,10 @@ let topUndefined: t<'a> => Js.undefined<'a> let top: t<'a> => option<'a> let isEmpty: t<'a> => bool let size: t<'a> => int +@deprecated("Use `forEach` instead") let forEachU: (t<'a>, 'a => unit) => unit let forEach: (t<'a>, 'a => unit) => unit +@deprecated("Use `dynamicPopIter` instead") let dynamicPopIterU: (t<'a>, 'a => unit) => unit /** diff --git a/belt/src/belt_Option.js b/belt/src/belt_Option.js index 8dfa304..dce4800 100644 --- a/belt/src/belt_Option.js +++ b/belt/src/belt_Option.js @@ -2,32 +2,20 @@ import * as Caml_option from "rescript/lib/es6/caml_option.js"; -function keepU(opt, p) { +function keep(opt, p) { if (opt !== undefined && p(Caml_option.valFromOption(opt))) { return opt; } } -function keep(opt, p) { - return keepU(opt, (function (x) { - return p(x); - })); -} - -function forEachU(opt, f) { +function forEach(opt, f) { if (opt !== undefined) { return f(Caml_option.valFromOption(opt)); } } -function forEach(opt, f) { - forEachU(opt, (function (x) { - f(x); - })); -} - function getExn(x) { if (x !== undefined) { return Caml_option.valFromOption(x); @@ -39,7 +27,7 @@ function getExn(x) { }); } -function mapWithDefaultU(opt, $$default, f) { +function mapWithDefault(opt, $$default, f) { if (opt !== undefined) { return f(Caml_option.valFromOption(opt)); } else { @@ -47,38 +35,20 @@ function mapWithDefaultU(opt, $$default, f) { } } -function mapWithDefault(opt, $$default, f) { - return mapWithDefaultU(opt, $$default, (function (x) { - return f(x); - })); -} - -function mapU(opt, f) { +function map(opt, f) { if (opt !== undefined) { return Caml_option.some(f(Caml_option.valFromOption(opt))); } } -function map(opt, f) { - return mapU(opt, (function (x) { - return f(x); - })); -} - -function flatMapU(opt, f) { +function flatMap(opt, f) { if (opt !== undefined) { return f(Caml_option.valFromOption(opt)); } } -function flatMap(opt, f) { - return flatMapU(opt, (function (x) { - return f(x); - })); -} - function getWithDefault(opt, $$default) { if (opt !== undefined) { return Caml_option.valFromOption(opt); @@ -103,7 +73,7 @@ function isNone(x) { return x === undefined; } -function eqU(a, b, f) { +function eq(a, b, f) { if (a !== undefined) { if (b !== undefined) { return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); @@ -115,13 +85,7 @@ function eqU(a, b, f) { } } -function eq(a, b, f) { - return eqU(a, b, (function (x, y) { - return f(x, y); - })); -} - -function cmpU(a, b, f) { +function cmp(a, b, f) { if (a !== undefined) { if (b !== undefined) { return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); @@ -135,11 +99,19 @@ function cmpU(a, b, f) { } } -function cmp(a, b, f) { - return cmpU(a, b, (function (x, y) { - return f(x, y); - })); -} +let keepU = keep; + +let forEachU = forEach; + +let mapWithDefaultU = mapWithDefault; + +let mapU = map; + +let flatMapU = flatMap; + +let eqU = eq; + +let cmpU = cmp; export { keepU, diff --git a/belt/src/belt_Option.res b/belt/src/belt_Option.res index 19145fa..3d6b18f 100644 --- a/belt/src/belt_Option.res +++ b/belt/src/belt_Option.res @@ -22,22 +22,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -let keepU = (opt, p) => +let keep = (opt, p) => switch opt { | Some(x) as some if p(x) => some | _ => None } -let keep = (opt, p) => keepU(opt, x => p(x)) - -let forEachU = (opt, f) => +let forEach = (opt, f) => switch opt { | Some(x) => f(x) | None => () } -let forEach = (opt, f) => forEachU(opt, x => f(x)) - let getExn = x => switch x { | Some(x) => x @@ -46,30 +42,24 @@ let getExn = x => external getUnsafe: option<'a> => 'a = "%identity" -let mapWithDefaultU = (opt, default, f) => +let mapWithDefault = (opt, default, f) => switch opt { | Some(x) => f(x) | None => default } -let mapWithDefault = (opt, default, f) => mapWithDefaultU(opt, default, x => f(x)) - -let mapU = (opt, f) => +let map = (opt, f) => switch opt { | Some(x) => Some(f(x)) | None => None } -let map = (opt, f) => mapU(opt, x => f(x)) - -let flatMapU = (opt, f) => +let flatMap = (opt, f) => switch opt { | Some(x) => f(x) | None => None } -let flatMap = (opt, f) => flatMapU(opt, x => f(x)) - let getWithDefault = (opt, default) => switch opt { | Some(x) => x @@ -90,7 +80,7 @@ let isSome = x => let isNone = x => x == None -let eqU = (a, b, f) => +let eq = (a, b, f) => switch a { | Some(a) => switch b { @@ -100,9 +90,7 @@ let eqU = (a, b, f) => | None => b == None } -let eq = (a, b, f) => eqU(a, b, (x, y) => f(x, y)) - -let cmpU = (a, b, f) => +let cmp = (a, b, f) => switch (a, b) { | (Some(a), Some(b)) => f(a, b) | (None, Some(_)) => -1 @@ -110,4 +98,10 @@ let cmpU = (a, b, f) => | (None, None) => 0 } -let cmp = (a, b, f) => cmpU(a, b, (x, y) => f(x, y)) +let cmpU = cmp +let eqU = eq +let flatMapU = flatMap +let forEachU = forEach +let keepU = keep +let mapU = map +let mapWithDefaultU = mapWithDefault diff --git a/belt/src/belt_Option.resi b/belt/src/belt_Option.resi index 31ab9b7..97f2a59 100644 --- a/belt/src/belt_Option.resi +++ b/belt/src/belt_Option.resi @@ -41,6 +41,7 @@ let someString: option = Some("hello") */ /** Uncurried version of `keep` */ +@deprecated("Use `keep` instead") let keepU: (option<'a>, 'a => bool) => option<'a> /** @@ -57,6 +58,7 @@ Belt.Option.keep(None, x => x > 5) /* returns `None` */ let keep: (option<'a>, 'a => bool) => option<'a> /** Uncurried version of `forEach` */ +@deprecated("Use `forEach` instead") let forEachU: (option<'a>, 'a => unit) => unit /** @@ -93,6 +95,7 @@ nor `Some(None(...)))` external getUnsafe: option<'a> => 'a = "%identity" /** Uncurried version of `mapWithDefault` */ +@deprecated("Use `mapWithDefault` instead") let mapWithDefaultU: (option<'a>, 'b, 'a => 'b) => 'b /** @@ -114,6 +117,7 @@ noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ let mapWithDefault: (option<'a>, 'b, 'a => 'b) => 'b /** Uncurried version of `map` */ +@deprecated("Use `map` instead") let mapU: (option<'a>, 'a => 'b) => option<'b> /** @@ -130,6 +134,7 @@ Belt.Option.map(None, x => x * x) /* None */ let map: (option<'a>, 'a => 'b) => option<'b> /** Uncurried version of `flatMap` */ +@deprecated("Use `flatMap` instead") let flatMapU: (option<'a>, 'a => option<'b>) => option<'b> /** @@ -221,6 +226,7 @@ let isNone: option<'a> => bool /** Uncurried version of `eq` */ +@deprecated("Use `eq` instead") let eqU: (option<'a>, option<'b>, ('a, 'b) => bool) => bool /** @@ -253,6 +259,7 @@ let eq: (option<'a>, option<'b>, ('a, 'b) => bool) => bool /** Uncurried version of `cmp` */ +@deprecated("Use `cmp` instead") let cmpU: (option<'a>, option<'b>, ('a, 'b) => int) => int /** diff --git a/belt/src/belt_Range.js b/belt/src/belt_Range.js index 6dc8c01..47f750e 100644 --- a/belt/src/belt_Range.js +++ b/belt/src/belt_Range.js @@ -1,19 +1,13 @@ -function forEachU(s, f, action) { +function forEach(s, f, action) { for(let i = s; i <= f; ++i){ action(i); } } -function forEach(s, f, action) { - forEachU(s, f, (function (a) { - action(a); - })); -} - -function everyU(_s, f, p) { +function every(_s, f, p) { while(true) { let s = _s; if (s > f) { @@ -27,13 +21,7 @@ function everyU(_s, f, p) { }; } -function every(s, f, p) { - return everyU(s, f, (function (a) { - return p(a); - })); -} - -function everyByU(s, f, step, p) { +function everyBy(s, f, step, p) { if (step > 0) { let _s = s; while(true) { @@ -52,13 +40,7 @@ function everyByU(s, f, step, p) { } } -function everyBy(s, f, step, p) { - return everyByU(s, f, step, (function (a) { - return p(a); - })); -} - -function someU(_s, f, p) { +function some(_s, f, p) { while(true) { let s = _s; if (s > f) { @@ -72,13 +54,7 @@ function someU(_s, f, p) { }; } -function some(s, f, p) { - return someU(s, f, (function (a) { - return p(a); - })); -} - -function someByU(s, f, step, p) { +function someBy(s, f, step, p) { if (step > 0) { let _s = s; while(true) { @@ -97,11 +73,15 @@ function someByU(s, f, step, p) { } } -function someBy(s, f, step, p) { - return someByU(s, f, step, (function (a) { - return p(a); - })); -} +let forEachU = forEach; + +let everyU = every; + +let everyByU = everyBy; + +let someU = some; + +let someByU = someBy; export { forEachU, diff --git a/belt/src/belt_Range.res b/belt/src/belt_Range.res index a4018ae..341c29f 100644 --- a/belt/src/belt_Range.res +++ b/belt/src/belt_Range.res @@ -22,22 +22,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -let forEachU = (s, f, action) => +let forEach = (s, f, action) => for i in s to f { (action(i): unit) } -let forEach = (s, f, action) => forEachU(s, f, a => action(a)) - -let rec everyU = (s, f, p) => +let rec every = (s, f, p) => if s > f { true } else { - p(s) && everyU(s + 1, f, p) + p(s) && every(s + 1, f, p) } -let every = (s, f, p) => everyU(s, f, a => p(a)) - let rec everyByAux = (s, f, ~step, p) => if s > f { true @@ -45,24 +41,20 @@ let rec everyByAux = (s, f, ~step, p) => p(s) && everyByAux(s + step, f, ~step, p) } -let everyByU = (s, f, ~step, p) => +let everyBy = (s, f, ~step, p) => if step > 0 { everyByAux(s, f, ~step, p) } else { true } /* return empty range `true` */ -let everyBy = (s, f, ~step, p) => everyByU(s, f, ~step, a => p(a)) - -let rec someU = (s, f, p) => +let rec some = (s, f, p) => if s > f { false } else { - p(s) || someU(s + 1, f, p) + p(s) || some(s + 1, f, p) } -let some = (s, f, p) => someU(s, f, a => p(a)) - let rec someByAux = (s, f, ~step, p) => if s > f { false @@ -70,11 +62,15 @@ let rec someByAux = (s, f, ~step, p) => p(s) || someByAux(s + step, f, ~step, p) } -let someByU = (s, f, ~step, p) => +let someBy = (s, f, ~step, p) => if step > 0 { someByAux(s, f, ~step, p) } else { false } /* return empty range, `false` */ -let someBy = (s, f, ~step, p) => someByU(s, f, ~step, a => p(a)) +let everyByU = everyBy +let everyU = every +let forEachU = forEach +let someByU = someBy +let someU = some diff --git a/belt/src/belt_Range.resi b/belt/src/belt_Range.resi index 3f805ab..d5a8e88 100644 --- a/belt/src/belt_Range.resi +++ b/belt/src/belt_Range.resi @@ -28,6 +28,7 @@ Internally it is relying on loops instead of creating new arrays, which makes it pretty performant and memory friendly. */ +@deprecated("Use `forEach` instead") let forEachU: (int, int, int => unit) => unit /** @@ -48,6 +49,7 @@ Belt.Range.forEach(0, 4, (i) => Js.log(i)) */ let forEach: (int, int, int => unit) => unit +@deprecated("Use `every` instead") let everyU: (int, int, int => bool) => bool /** @@ -62,6 +64,7 @@ Belt.Range.every(0, 4, (i) => i < 4) /* false */ */ let every: (int, int, int => bool) => bool +@deprecated("Use `everyBy` instead") let everyByU: (int, int, ~step: int, int => bool) => bool /** @@ -78,6 +81,7 @@ Belt.Range.everyBy(0, 4, ~step=2, (i) => mod(i, 2) === 0) /* true */ */ let everyBy: (int, int, ~step: int, int => bool) => bool +@deprecated("Use `some` instead") let someU: (int, int, int => bool) => bool /** @@ -93,6 +97,7 @@ Belt.Range.some(0, 4, (i) => i > 2) /* true */ */ let some: (int, int, int => bool) => bool +@deprecated("Use `someBy` instead") let someByU: (int, int, ~step: int, int => bool) => bool /** diff --git a/belt/src/belt_Result.js b/belt/src/belt_Result.js index e3594b9..8e9dce6 100644 --- a/belt/src/belt_Result.js +++ b/belt/src/belt_Result.js @@ -12,7 +12,7 @@ function getExn(x) { }); } -function mapWithDefaultU(opt, $$default, f) { +function mapWithDefault(opt, $$default, f) { if (opt.TAG === "Ok") { return f(opt._0); } else { @@ -20,13 +20,7 @@ function mapWithDefaultU(opt, $$default, f) { } } -function mapWithDefault(opt, $$default, f) { - return mapWithDefaultU(opt, $$default, (function (x) { - return f(x); - })); -} - -function mapU(opt, f) { +function map(opt, f) { if (opt.TAG === "Ok") { return { TAG: "Ok", @@ -40,13 +34,7 @@ function mapU(opt, f) { } } -function map(opt, f) { - return mapU(opt, (function (x) { - return f(x); - })); -} - -function flatMapU(opt, f) { +function flatMap(opt, f) { if (opt.TAG === "Ok") { return f(opt._0); } else { @@ -57,12 +45,6 @@ function flatMapU(opt, f) { } } -function flatMap(opt, f) { - return flatMapU(opt, (function (x) { - return f(x); - })); -} - function getWithDefault(opt, $$default) { if (opt.TAG === "Ok") { return opt._0; @@ -87,7 +69,7 @@ function isError(x) { } } -function eqU(a, b, f) { +function eq(a, b, f) { if (a.TAG === "Ok") { if (b.TAG === "Ok") { return f(a._0, b._0); @@ -101,13 +83,7 @@ function eqU(a, b, f) { } } -function eq(a, b, f) { - return eqU(a, b, (function (x, y) { - return f(x, y); - })); -} - -function cmpU(a, b, f) { +function cmp(a, b, f) { if (a.TAG === "Ok") { if (b.TAG === "Ok") { return f(a._0, b._0); @@ -121,11 +97,15 @@ function cmpU(a, b, f) { } } -function cmp(a, b, f) { - return cmpU(a, b, (function (x, y) { - return f(x, y); - })); -} +let mapWithDefaultU = mapWithDefault; + +let mapU = map; + +let flatMapU = flatMap; + +let eqU = eq; + +let cmpU = cmp; export { getExn, diff --git a/belt/src/belt_Result.res b/belt/src/belt_Result.res index 08d2193..a6ded4b 100644 --- a/belt/src/belt_Result.res +++ b/belt/src/belt_Result.res @@ -32,30 +32,24 @@ let getExn = x => | Error(_) => raise(Not_found) } -let mapWithDefaultU = (opt, default, f) => +let mapWithDefault = (opt, default, f) => switch opt { | Ok(x) => f(x) | Error(_) => default } -let mapWithDefault = (opt, default, f) => mapWithDefaultU(opt, default, x => f(x)) - -let mapU = (opt, f) => +let map = (opt, f) => switch opt { | Ok(x) => Ok(f(x)) | Error(y) => Error(y) } -let map = (opt, f) => mapU(opt, x => f(x)) - -let flatMapU = (opt, f) => +let flatMap = (opt, f) => switch opt { | Ok(x) => f(x) | Error(y) => Error(y) } -let flatMap = (opt, f) => flatMapU(opt, x => f(x)) - let getWithDefault = (opt, default) => switch opt { | Ok(x) => x @@ -74,7 +68,7 @@ let isError = x => | Error(_) => true } -let eqU = (a, b, f) => +let eq = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(a, b) | (Error(_), Ok(_)) @@ -82,9 +76,7 @@ let eqU = (a, b, f) => | (Error(_), Error(_)) => true } -let eq = (a, b, f) => eqU(a, b, (x, y) => f(x, y)) - -let cmpU = (a, b, f) => +let cmp = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(a, b) | (Error(_), Ok(_)) => -1 @@ -92,4 +84,8 @@ let cmpU = (a, b, f) => | (Error(_), Error(_)) => 0 } -let cmp = (a, b, f) => cmpU(a, b, (x, y) => f(x, y)) +let cmpU = cmp +let eqU = eq +let flatMapU = flatMap +let mapU = map +let mapWithDefaultU = mapWithDefault diff --git a/belt/src/belt_Result.resi b/belt/src/belt_Result.resi index f3821d5..f3949d7 100644 --- a/belt/src/belt_Result.resi +++ b/belt/src/belt_Result.resi @@ -46,6 +46,7 @@ Belt.Result.getExn(Belt.Result.Error("Invalid data")) /* raises exception */ */ let getExn: t<'a, 'b> => 'a +@deprecated("Use `mapWithDefault` instead") let mapWithDefaultU: (t<'a, 'c>, 'b, 'a => 'b) => 'b /** `mapWithDefault(res, default, f)`: When res is `Ok(n)`, returns `f(n)`, @@ -63,6 +64,7 @@ Belt.Result.mapWithDefault(error, 0, (x) => x / 2) == 0 */ let mapWithDefault: (t<'a, 'c>, 'b, 'a => 'b) => 'b +@deprecated("Use `map` instead") let mapU: (t<'a, 'c>, 'a => 'b) => t<'b, 'c> /** `map(res, f)`: When res is `Ok(n)`, returns `Ok(f(n))`. Otherwise returns res @@ -81,6 +83,7 @@ Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") */ let map: (t<'a, 'c>, 'a => 'b) => t<'b, 'c> +@deprecated("Use `flatMap` instead") let flatMapU: (t<'a, 'c>, 'a => t<'b, 'c>) => t<'b, 'c> /** `flatMap(res, f)`: When res is `Ok(n)`, returns `f(n)`. Otherwise, returns res @@ -132,6 +135,7 @@ it is the `Ok(n)` variant. */ let isError: t<'a, 'b> => bool +@deprecated("Use `eq` instead") let eqU: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool /** `eq(res1, res2, f)`: Determine if two `Belt.Result` variables are equal with @@ -164,6 +168,7 @@ Belt.Result.eq(bad1, bad2, mod10equal) == true */ let eq: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool +@deprecated("Use `cmp` instead") let cmpU: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => int) => int /** `cmp(res1, res2, f)`: Compare two `Belt.Result` variables with respect to a diff --git a/belt/src/belt_Set.js b/belt/src/belt_Set.js index e2046a6..af5497c 100644 --- a/belt/src/belt_Set.js +++ b/belt/src/belt_Set.js @@ -122,61 +122,31 @@ function eq(m, n) { return Belt_SetDict.eq(m.data, n.data, m.cmp); } -function forEachU(m, f) { - Belt_SetDict.forEachU(m.data, f); -} - function forEach(m, f) { - Belt_SetDict.forEachU(m.data, (function (a) { - f(a); - })); -} - -function reduceU(m, acc, f) { - return Belt_SetDict.reduceU(m.data, acc, f); + Belt_SetDict.forEach(m.data, f); } function reduce(m, acc, f) { - return reduceU(m, acc, (function (a, b) { - return f(a, b); - })); -} - -function everyU(m, f) { - return Belt_SetDict.everyU(m.data, f); + return Belt_SetDict.reduce(m.data, acc, f); } function every(m, f) { - return Belt_SetDict.everyU(m.data, (function (a) { - return f(a); - })); -} - -function someU(m, f) { - return Belt_SetDict.someU(m.data, f); + return Belt_SetDict.every(m.data, f); } function some(m, f) { - return Belt_SetDict.someU(m.data, (function (a) { - return f(a); - })); + return Belt_SetDict.some(m.data, f); } -function keepU(m, f) { +function keep(m, f) { return { cmp: m.cmp, - data: Belt_SetDict.keepU(m.data, f) + data: Belt_SetDict.keep(m.data, f) }; } -function keep(m, f) { - return keepU(m, (function (a) { - return f(a); - })); -} - -function partitionU(m, f) { - let match = Belt_SetDict.partitionU(m.data, f); +function partition(m, f) { + let match = Belt_SetDict.partition(m.data, f); let cmp = m.cmp; return [ { @@ -190,12 +160,6 @@ function partitionU(m, f) { ]; } -function partition(m, f) { - return partitionU(m, (function (a) { - return f(a); - })); -} - function size(m) { return Belt_SetDict.size(m.data); } @@ -275,6 +239,18 @@ let $$String; let Dict; +let forEachU = forEach; + +let reduceU = reduce; + +let everyU = every; + +let someU = some; + +let keepU = keep; + +let partitionU = partition; + export { Int, $$String, diff --git a/belt/src/belt_Set.res b/belt/src/belt_Set.res index dbfdd3a..70e2dd9 100644 --- a/belt/src/belt_Set.res +++ b/belt/src/belt_Set.res @@ -101,27 +101,21 @@ let cmp = (m, n) => { let eq = (m, n) => Dict.eq(~cmp=m.cmp, m.data, n.data) -let forEachU = (m, f) => Dict.forEachU(m.data, f) -let forEach = (m, f) => forEachU(m, a => f(a)) +let forEach = (m, f) => Dict.forEach(m.data, f) -let reduceU = (m, acc, f) => Dict.reduceU(m.data, acc, f) -let reduce = (m, acc, f) => reduceU(m, acc, (a, b) => f(a, b)) +let reduce = (m, acc, f) => Dict.reduce(m.data, acc, f) -let everyU = (m, f) => Dict.everyU(m.data, f) -let every = (m, f) => everyU(m, a => f(a)) +let every = (m, f) => Dict.every(m.data, f) -let someU = (m, f) => Dict.someU(m.data, f) -let some = (m, f) => someU(m, a => f(a)) +let some = (m, f) => Dict.some(m.data, f) -let keepU = (m, f) => {cmp: m.cmp, data: Dict.keepU(m.data, f)} -let keep = (m, f) => keepU(m, a => f(a)) +let keep = (m, f) => {cmp: m.cmp, data: Dict.keep(m.data, f)} -let partitionU = (m, f) => { - let (l, r) = Dict.partitionU(m.data, f) +let partition = (m, f) => { + let (l, r) = Dict.partition(m.data, f) let cmp = m.cmp ({data: l, cmp}, {data: r, cmp}) } -let partition = (m, f) => partitionU(m, a => f(a)) let size = m => Dict.size(m.data) let toList = m => Dict.toList(m.data) @@ -162,3 +156,10 @@ let packIdData = (type value identity, ~id: id, ~data) => { } let checkInvariantInternal = d => Dict.checkInvariantInternal(d.data) + +let everyU = every +let forEachU = forEach +let keepU = keep +let partitionU = partition +let reduceU = reduce +let someU = some diff --git a/belt/src/belt_Set.resi b/belt/src/belt_Set.resi index 5a6319e..343c7dd 100644 --- a/belt/src/belt_Set.resi +++ b/belt/src/belt_Set.resi @@ -297,6 +297,7 @@ let eq: (t<'value, 'id>, t<'value, 'id>) => bool /** Same as [forEach](#forEach) but takes uncurried functon. */ +@deprecated("Use `forEach` instead") let forEachU: (t<'value, 'id>, 'value => unit) => unit /** @@ -315,6 +316,7 @@ acc /* [6,5,3,2] */ */ let forEach: (t<'value, 'id>, 'value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a /** @@ -331,6 +333,7 @@ s0->Belt.Set.reduce(list{}, (acc, element) => */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t<'value, 'id>, 'value => bool) => bool /** @@ -347,6 +350,7 @@ s0->Belt.Set.every(isEven) /* true */ */ let every: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'value, 'id>, 'value => bool) => bool /** @@ -363,6 +367,7 @@ s0->Belt.Set.some(isOdd) /* true */ */ let some: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t<'value, 'id>, 'value => bool) => t<'value, 'id> /** @@ -381,6 +386,7 @@ s1->Belt.Set.toArray /* [2,4] */ */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> +@deprecated("Use `partition` instead") let partitionU: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) /** diff --git a/belt/src/belt_SetDict.js b/belt/src/belt_SetDict.js index 4231c26..ddf9fbb 100644 --- a/belt/src/belt_SetDict.js +++ b/belt/src/belt_SetDict.js @@ -272,27 +272,27 @@ let cmp = Belt_internalAVLset.cmp; let eq = Belt_internalAVLset.eq; -let forEachU = Belt_internalAVLset.forEachU; +let forEachU = Belt_internalAVLset.forEach; let forEach = Belt_internalAVLset.forEach; -let reduceU = Belt_internalAVLset.reduceU; +let reduceU = Belt_internalAVLset.reduce; let reduce = Belt_internalAVLset.reduce; -let everyU = Belt_internalAVLset.everyU; +let everyU = Belt_internalAVLset.every; let every = Belt_internalAVLset.every; -let someU = Belt_internalAVLset.someU; +let someU = Belt_internalAVLset.some; let some = Belt_internalAVLset.some; -let keepU = Belt_internalAVLset.keepSharedU; +let keepU = Belt_internalAVLset.keepShared; let keep = Belt_internalAVLset.keepShared; -let partitionU = Belt_internalAVLset.partitionSharedU; +let partitionU = Belt_internalAVLset.partitionShared; let partition = Belt_internalAVLset.partitionShared; diff --git a/belt/src/belt_SetDict.res b/belt/src/belt_SetDict.res index 60337c3..7758446 100644 --- a/belt/src/belt_SetDict.res +++ b/belt/src/belt_SetDict.res @@ -235,13 +235,13 @@ let isEmpty = N.isEmpty let cmp = N.cmp let eq = N.eq let has = N.has -let forEachU = N.forEachU +let forEachU = N.forEach let forEach = N.forEach -let reduceU = N.reduceU +let reduceU = N.reduce let reduce = N.reduce -let everyU = N.everyU +let everyU = N.every let every = N.every -let someU = N.someU +let someU = N.some let some = N.some let size = N.size let toList = N.toList @@ -257,8 +257,8 @@ let getUndefined = N.getUndefined let fromSortedArrayUnsafe = N.fromSortedArrayUnsafe let subset = N.subset let keep = N.keepShared -let keepU = N.keepSharedU -let partitionU = N.partitionSharedU +let keepU = N.keepShared +let partitionU = N.partitionShared let partition = N.partitionShared let checkInvariantInternal = N.checkInvariantInternal diff --git a/belt/src/belt_SetDict.resi b/belt/src/belt_SetDict.resi index d736f27..07efa59 100644 --- a/belt/src/belt_SetDict.resi +++ b/belt/src/belt_SetDict.resi @@ -308,6 +308,7 @@ let eq: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => bool /** Same as [forEach](##forEach) but takes uncurried functon. */ +@deprecated("Use `forEach` instead") let forEachU: (t<'value, 'id>, 'value => unit) => unit /** @@ -329,6 +330,7 @@ acc /* [6,5,3,2] */ */ let forEach: (t<'value, 'id>, 'value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a /** @@ -348,6 +350,7 @@ s0->Belt.Set.Dict.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t<'value, 'id>, 'value => bool) => bool /** @@ -369,6 +372,7 @@ s0->Belt.Set.Dict.every(isEven) /* true */ */ let every: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `some` instead") let someU: (t<'value, 'id>, 'value => bool) => bool /** @@ -390,6 +394,7 @@ s0->Belt.Set.Dict.some(isOdd) /* true */ */ let some: (t<'value, 'id>, 'value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t<'value, 'id>, 'value => bool) => t<'value, 'id> /** @@ -413,6 +418,7 @@ s1->Belt.Set.Dict.toArray /* [2,4] */ */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> +@deprecated("Use `partition` instead") let partitionU: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) /** diff --git a/belt/src/belt_SetInt.js b/belt/src/belt_SetInt.js index 6c172f6..3690d69 100644 --- a/belt/src/belt_SetInt.js +++ b/belt/src/belt_SetInt.js @@ -269,27 +269,27 @@ let cmp = Belt_internalSetInt.cmp; let eq = Belt_internalSetInt.eq; -let forEachU = Belt_internalAVLset.forEachU; +let forEachU = Belt_internalAVLset.forEach; let forEach = Belt_internalAVLset.forEach; -let reduceU = Belt_internalAVLset.reduceU; +let reduceU = Belt_internalAVLset.reduce; let reduce = Belt_internalAVLset.reduce; -let everyU = Belt_internalAVLset.everyU; +let everyU = Belt_internalAVLset.every; let every = Belt_internalAVLset.every; -let someU = Belt_internalAVLset.someU; +let someU = Belt_internalAVLset.some; let some = Belt_internalAVLset.some; -let keepU = Belt_internalAVLset.keepSharedU; +let keepU = Belt_internalAVLset.keepShared; let keep = Belt_internalAVLset.keepShared; -let partitionU = Belt_internalAVLset.partitionSharedU; +let partitionU = Belt_internalAVLset.partitionShared; let partition = Belt_internalAVLset.partitionShared; diff --git a/belt/src/belt_SetInt.res b/belt/src/belt_SetInt.res index 8d75c14..0f294c1 100644 --- a/belt/src/belt_SetInt.res +++ b/belt/src/belt_SetInt.res @@ -14,17 +14,11 @@ let maximum = N.maximum let maxUndefined = N.maxUndefined let forEach = N.forEach -let forEachU = N.forEachU let reduce = N.reduce -let reduceU = N.reduceU let every = N.every -let everyU = N.everyU let some = N.some -let someU = N.someU let keep = N.keepShared -let keepU = N.keepSharedU let partition = N.partitionShared -let partitionU = N.partitionSharedU let size = N.size let toList = N.toList @@ -225,3 +219,10 @@ let rec diff = (s1: t, s2: t) => N.joinShared(ll, v1, rr) } } + +let forEachU = forEach +let reduceU = reduce +let everyU = every +let someU = some +let keepU = keep +let partitionU = partition diff --git a/belt/src/belt_SetInt.resi b/belt/src/belt_SetInt.resi index ef7a9fd..4a31ca7 100644 --- a/belt/src/belt_SetInt.resi +++ b/belt/src/belt_SetInt.resi @@ -83,6 +83,7 @@ equal elements. */ let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** @@ -90,11 +91,13 @@ let forEachU: (t, value => unit) => unit */ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -103,6 +106,7 @@ unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -111,6 +115,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -118,6 +123,7 @@ let keepU: (t, value => bool) => t */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt/src/belt_SetString.js b/belt/src/belt_SetString.js index 3322ff2..581ebb5 100644 --- a/belt/src/belt_SetString.js +++ b/belt/src/belt_SetString.js @@ -269,27 +269,27 @@ let cmp = Belt_internalSetString.cmp; let eq = Belt_internalSetString.eq; -let forEachU = Belt_internalAVLset.forEachU; +let forEachU = Belt_internalAVLset.forEach; let forEach = Belt_internalAVLset.forEach; -let reduceU = Belt_internalAVLset.reduceU; +let reduceU = Belt_internalAVLset.reduce; let reduce = Belt_internalAVLset.reduce; -let everyU = Belt_internalAVLset.everyU; +let everyU = Belt_internalAVLset.every; let every = Belt_internalAVLset.every; -let someU = Belt_internalAVLset.someU; +let someU = Belt_internalAVLset.some; let some = Belt_internalAVLset.some; -let keepU = Belt_internalAVLset.keepSharedU; +let keepU = Belt_internalAVLset.keepShared; let keep = Belt_internalAVLset.keepShared; -let partitionU = Belt_internalAVLset.partitionSharedU; +let partitionU = Belt_internalAVLset.partitionShared; let partition = Belt_internalAVLset.partitionShared; diff --git a/belt/src/belt_SetString.res b/belt/src/belt_SetString.res index 972aa53..73d20bb 100644 --- a/belt/src/belt_SetString.res +++ b/belt/src/belt_SetString.res @@ -14,17 +14,11 @@ let maximum = N.maximum let maxUndefined = N.maxUndefined let forEach = N.forEach -let forEachU = N.forEachU let reduce = N.reduce -let reduceU = N.reduceU let every = N.every -let everyU = N.everyU let some = N.some -let someU = N.someU let keep = N.keepShared -let keepU = N.keepSharedU let partition = N.partitionShared -let partitionU = N.partitionSharedU let size = N.size let toList = N.toList @@ -225,3 +219,10 @@ let rec diff = (s1: t, s2: t) => N.joinShared(ll, v1, rr) } } + +let forEachU = forEach +let reduceU = reduce +let everyU = every +let someU = some +let keepU = keep +let partitionU = partition diff --git a/belt/src/belt_SetString.resi b/belt/src/belt_SetString.resi index cffbc13..4c25b3f 100644 --- a/belt/src/belt_SetString.resi +++ b/belt/src/belt_SetString.resi @@ -83,6 +83,7 @@ equal elements. */ let eq: (t, t) => bool +@deprecated("Use `forEach` instead") let forEachU: (t, value => unit) => unit /** @@ -90,11 +91,13 @@ let forEachU: (t, value => unit) => unit */ let forEach: (t, value => unit) => unit +@deprecated("Use `reduce` instead") let reduceU: (t, 'a, ('a, value) => 'a) => 'a /** Iterate in increasing order. */ let reduce: (t, 'a, ('a, value) => 'a) => 'a +@deprecated("Use `every` instead") let everyU: (t, value => bool) => bool /** @@ -103,6 +106,7 @@ unspecified. */ let every: (t, value => bool) => bool +@deprecated("Use `some` instead") let someU: (t, value => bool) => bool /** @@ -111,6 +115,7 @@ let someU: (t, value => bool) => bool */ let some: (t, value => bool) => bool +@deprecated("Use `keep` instead") let keepU: (t, value => bool) => t /** @@ -118,6 +123,7 @@ let keepU: (t, value => bool) => t */ let keep: (t, value => bool) => t +@deprecated("Use `partition` instead") let partitionU: (t, value => bool) => (t, t) /** diff --git a/belt/src/belt_SortArray.js b/belt/src/belt_SortArray.js index 1181083..1633e57 100644 --- a/belt/src/belt_SortArray.js +++ b/belt/src/belt_SortArray.js @@ -19,7 +19,7 @@ function sortedLengthAuxMore(xs, _prec, _acc, len, lt) { }; } -function strictlySortedLengthU(xs, lt) { +function strictlySortedLength(xs, lt) { let len = xs.length; if (len === 0 || len === 1) { return len; @@ -50,13 +50,7 @@ function strictlySortedLengthU(xs, lt) { } } -function strictlySortedLength(xs, lt) { - return strictlySortedLengthU(xs, (function (x, y) { - return lt(x, y); - })); -} - -function isSortedU(a, cmp) { +function isSorted(a, cmp) { let len = a.length; if (len === 0) { return true; @@ -77,12 +71,6 @@ function isSortedU(a, cmp) { } } -function isSorted(a, cmp) { - return isSortedU(a, (function (x, y) { - return cmp(x, y); - })); -} - function merge(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; @@ -120,7 +108,7 @@ function merge(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) }; } -function unionU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { +function union(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; let _i1 = src1ofs; @@ -183,13 +171,7 @@ function unionU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) }; } -function union(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { - return unionU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (function (x, y) { - return cmp(x, y); - })); -} - -function intersectU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { +function intersect(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; let _i1 = src1ofs; @@ -238,13 +220,7 @@ function intersectU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, }; } -function intersect(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { - return intersectU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (function (x, y) { - return cmp(x, y); - })); -} - -function diffU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { +function diff(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; let _i1 = src1ofs; @@ -299,12 +275,6 @@ function diffU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) }; } -function diff(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) { - return diffU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (function (x, y) { - return cmp(x, y); - })); -} - function insertionSort(src, srcofs, dst, dstofs, len, cmp) { for(let i = 0; i < len; ++i){ let e = src[srcofs + i | 0]; @@ -328,7 +298,7 @@ function sortTo(src, srcofs, dst, dstofs, len, cmp) { merge(src, srcofs + l2 | 0, l1, dst, dstofs + l1 | 0, l2, dst, dstofs, cmp); } -function stableSortInPlaceByU(a, cmp) { +function stableSortInPlaceBy(a, cmp) { let l = a.length; if (l <= 5) { return insertionSort(a, 0, a, 0, l, cmp); @@ -341,25 +311,13 @@ function stableSortInPlaceByU(a, cmp) { merge(a, l2, l1, t, 0, l2, a, 0, cmp); } -function stableSortInPlaceBy(a, cmp) { - stableSortInPlaceByU(a, (function (x, y) { - return cmp(x, y); - })); -} - -function stableSortByU(a, cmp) { +function stableSortBy(a, cmp) { let b = a.slice(0); - stableSortInPlaceByU(b, cmp); + stableSortInPlaceBy(b, cmp); return b; } -function stableSortBy(a, cmp) { - return stableSortByU(a, (function (x, y) { - return cmp(x, y); - })); -} - -function binarySearchByU(sorted, key, cmp) { +function binarySearchBy(sorted, key, cmp) { let len = sorted.length; if (len === 0) { return -1; @@ -409,16 +367,26 @@ function binarySearchByU(sorted, key, cmp) { } } -function binarySearchBy(sorted, key, cmp) { - return binarySearchByU(sorted, key, (function (x, y) { - return cmp(x, y); - })); -} - let Int; let $$String; +let strictlySortedLengthU = strictlySortedLength; + +let isSortedU = isSorted; + +let stableSortInPlaceByU = stableSortInPlaceBy; + +let stableSortByU = stableSortBy; + +let binarySearchByU = binarySearchBy; + +let unionU = union; + +let intersectU = intersect; + +let diffU = diff; + export { Int, $$String, diff --git a/belt/src/belt_SortArray.res b/belt/src/belt_SortArray.res index ee4ee55..3e32914 100644 --- a/belt/src/belt_SortArray.res +++ b/belt/src/belt_SortArray.res @@ -52,7 +52,7 @@ let rec sortedLengthAuxLess = (xs, prec, acc, len, lt) => } } -let strictlySortedLengthU = (xs, lt) => { +let strictlySortedLength = (xs, lt) => { let len = A.length(xs) switch len { | 0 | 1 => len @@ -70,8 +70,6 @@ let strictlySortedLengthU = (xs, lt) => { } } -let strictlySortedLength = (xs, lt) => strictlySortedLengthU(xs, (x, y) => lt(x, y)) - let rec isSortedAux = (a, i, cmp, last_bound) => /* when `i = len - 1`, it reaches the last element */ if i == last_bound { @@ -82,7 +80,7 @@ let rec isSortedAux = (a, i, cmp, last_bound) => false } -let isSortedU = (a, cmp) => { +let isSorted = (a, cmp) => { let len = A.length(a) if len == 0 { true @@ -91,8 +89,6 @@ let isSortedU = (a, cmp) => { } } -let isSorted = (a, cmp) => isSortedU(a, (x, y) => cmp(x, y)) - let cutoff = 5 let merge = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { @@ -119,7 +115,7 @@ let merge = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => loop(src1ofs, A.getUnsafe(src, src1ofs), src2ofs, A.getUnsafe(src2, src2ofs), dstofs) } -let unionU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { +let union = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { let src1r = src1ofs + src1len let src2r = src2ofs + src2len let rec loop = (i1, s1, i2, s2, d) => { @@ -165,10 +161,7 @@ let unionU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) = loop(src1ofs, A.getUnsafe(src, src1ofs), src2ofs, A.getUnsafe(src2, src2ofs), dstofs) } -let union = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => - unionU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (x, y) => cmp(x, y)) - -let intersectU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { +let intersect = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { let src1r = src1ofs + src1len let src2r = src2ofs + src2len let rec loop = (i1, s1, i2, s2, d) => { @@ -205,10 +198,7 @@ let intersectU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cm loop(src1ofs, A.getUnsafe(src, src1ofs), src2ofs, A.getUnsafe(src2, src2ofs), dstofs) } -let intersect = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => - intersectU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (x, y) => cmp(x, y)) - -let diffU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { +let diff = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => { let src1r = src1ofs + src1len let src2r = src2ofs + src2len let rec loop = (i1, s1, i2, s2, d) => { @@ -247,9 +237,6 @@ let diffU = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => loop(src1ofs, A.getUnsafe(src, src1ofs), src2ofs, A.getUnsafe(src2, src2ofs), dstofs) } -let diff = (src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, cmp) => - diffU(src, src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs, (x, y) => cmp(x, y)) - /* `<=` alone is not enough for stable sort */ let insertionSort = (src, srcofs, dst, dstofs, len, cmp) => for i in 0 to len - 1 { @@ -273,7 +260,7 @@ let rec sortTo = (src, srcofs, dst, dstofs, len, cmp) => merge(src, srcofs + l2, l1, dst, dstofs + l1, l2, dst, dstofs, cmp) } -let stableSortInPlaceByU = (a, cmp) => { +let stableSortInPlaceBy = (a, cmp) => { let l = A.length(a) if l <= cutoff { insertionSort(a, 0, a, 0, l, cmp) @@ -287,15 +274,12 @@ let stableSortInPlaceByU = (a, cmp) => { } } -let stableSortInPlaceBy = (a, cmp) => stableSortInPlaceByU(a, (x, y) => cmp(x, y)) - -let stableSortByU = (a, cmp) => { +let stableSortBy = (a, cmp) => { let b = A.copy(a) - stableSortInPlaceByU(b, cmp) + stableSortInPlaceBy(b, cmp) b } -let stableSortBy = (a, cmp) => stableSortByU(a, (x, y) => cmp(x, y)) /* `binarySearchAux arr lo hi key cmp` range [lo, hi] @@ -330,7 +314,7 @@ let rec binarySearchAux = (arr, lo, hi, key, cmp) => { } } -let binarySearchByU = (sorted, key, cmp): int => { +let binarySearchBy = (sorted, key, cmp): int => { let len = A.length(sorted) if len == 0 { -1 @@ -351,4 +335,11 @@ let binarySearchByU = (sorted, key, cmp): int => { } } -let binarySearchBy = (sorted, key, cmp) => binarySearchByU(sorted, key, (x, y) => cmp(x, y)) +let binarySearchByU = binarySearchBy +let diffU = diff +let intersectU = intersect +let isSortedU = isSorted +let stableSortByU = stableSortBy +let stableSortInPlaceByU = stableSortInPlaceBy +let strictlySortedLengthU = strictlySortedLength +let unionU = union diff --git a/belt/src/belt_SortArray.resi b/belt/src/belt_SortArray.resi index 24d08df..372a225 100644 --- a/belt/src/belt_SortArray.resi +++ b/belt/src/belt_SortArray.resi @@ -36,6 +36,7 @@ Specalized when key type is `string`, more efficient than the generic type */ module String = Belt_SortArrayString +@deprecated("Use `strictlySortedLength` instead") let strictlySortedLengthU: (array<'a>, ('a, 'a) => bool) => int /** @@ -55,15 +56,18 @@ Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 */ let strictlySortedLength: (array<'a>, ('a, 'a) => bool) => int +@deprecated("Use `isSorted` instead") let isSortedU: (array<'a>, ('a, 'a) => int) => bool /** `isSorted(arr, cmp)`: Returns true if array is increasingly sorted (equal is okay) */ let isSorted: (array<'a>, ('a, 'a) => int) => bool +@deprecated("Use `stableSortInPlaceBy` instead") let stableSortInPlaceByU: (array<'a>, ('a, 'a) => int) => unit let stableSortInPlaceBy: (array<'a>, ('a, 'a) => int) => unit +@deprecated("Use `stableSortBy` instead") let stableSortByU: (array<'a>, ('a, 'a) => int) => array<'a> /** `stableSortBy(xs, cmp)`: Returns a fresh array Sort `xs` in place using @@ -72,6 +76,7 @@ be preserved */ let stableSortBy: (array<'a>, ('a, 'a) => int) => array<'a> +@deprecated("Use `binarySearchBy` instead") let binarySearchByU: (array<'a>, 'a, ('a, 'a) => int) => int /** @@ -95,6 +100,7 @@ lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 */ let binarySearchBy: (array<'a>, 'a, ('a, 'a) => int) => int +@deprecated("Use `union` instead") let unionU: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int /** `union src src1ofs src1len src2 src2ofs src2len dst dstofs cmp` assume `src` and @@ -103,6 +109,7 @@ also assume that `dst` is large enough to store all elements */ let union: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int +@deprecated("Use `intersect` instead") let intersectU: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int /** `union src src1ofs src1len src2 src2ofs src2len dst dstofs cmp` @@ -111,5 +118,6 @@ let intersectU: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, */ let intersect: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int +@deprecated("Use `diff` instead") let diffU: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int let diff: (array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int) => int diff --git a/belt/src/belt_internalAVLset.js b/belt/src/belt_internalAVLset.js index b25c0d9..3772d6d 100644 --- a/belt/src/belt_internalAVLset.js +++ b/belt/src/belt_internalAVLset.js @@ -163,45 +163,33 @@ function stackAllLeft(_v, _s) { }; } -function forEachU(_n, f) { +function forEach(_n, f) { while(true) { let n = _n; if (n === undefined) { return; } - forEachU(n.l, f); + forEach(n.l, f); f(n.v); _n = n.r; continue; }; } -function forEach(n, f) { - forEachU(n, (function (a) { - f(a); - })); -} - -function reduceU(_s, _accu, f) { +function reduce(_s, _accu, f) { while(true) { let accu = _accu; let s = _s; if (s === undefined) { return accu; } - _accu = f(reduceU(s.l, accu, f), s.v); + _accu = f(reduce(s.l, accu, f), s.v); _s = s.r; continue; }; } -function reduce(s, accu, f) { - return reduceU(s, accu, (function (a, b) { - return f(a, b); - })); -} - -function everyU(_n, p) { +function every(_n, p) { while(true) { let n = _n; if (n === undefined) { @@ -210,7 +198,7 @@ function everyU(_n, p) { if (!p(n.v)) { return false; } - if (!everyU(n.l, p)) { + if (!every(n.l, p)) { return false; } _n = n.r; @@ -218,13 +206,7 @@ function everyU(_n, p) { }; } -function every(n, p) { - return everyU(n, (function (a) { - return p(a); - })); -} - -function someU(_n, p) { +function some(_n, p) { while(true) { let n = _n; if (n === undefined) { @@ -233,7 +215,7 @@ function someU(_n, p) { if (p(n.v)) { return true; } - if (someU(n.l, p)) { + if (some(n.l, p)) { return true; } _n = n.r; @@ -241,12 +223,6 @@ function someU(_n, p) { }; } -function some(n, p) { - return someU(n, (function (a) { - return p(a); - })); -} - function addMinElement(n, v) { if (n !== undefined) { return bal(addMinElement(n.l, v), n.v, n.r); @@ -295,7 +271,7 @@ function concatShared(t1, t2) { return joinShared(t1, v.contents, t2r); } -function partitionSharedU(n, p) { +function partitionShared(n, p) { if (n === undefined) { return [ undefined, @@ -303,11 +279,11 @@ function partitionSharedU(n, p) { ]; } let value = n.v; - let match = partitionSharedU(n.l, p); + let match = partitionShared(n.l, p); let lf = match[1]; let lt = match[0]; let pv = p(value); - let match$1 = partitionSharedU(n.r, p); + let match$1 = partitionShared(n.r, p); let rf = match$1[1]; let rt = match$1[0]; if (pv) { @@ -323,12 +299,6 @@ function partitionSharedU(n, p) { } } -function partitionShared(n, p) { - return partitionSharedU(n, (function (a) { - return p(a); - })); -} - function lengthNode(n) { let l = n.l; let r = n.r; @@ -384,7 +354,7 @@ function checkInvariantInternal(_v) { RE_EXN_ID: "Assert_failure", _1: [ "belt_internalAVLset.res", - 319, + 310, 4 ] } @@ -541,16 +511,16 @@ function fromSortedArrayUnsafe(arr) { return fromSortedArrayAux(arr, 0, arr.length); } -function keepSharedU(n, p) { +function keepShared(n, p) { if (n === undefined) { return; } let v = n.v; let l = n.l; let r = n.r; - let newL = keepSharedU(l, p); + let newL = keepShared(l, p); let pv = p(v); - let newR = keepSharedU(r, p); + let newR = keepShared(r, p); if (pv) { if (l === newL && r === newR) { return n; @@ -562,13 +532,7 @@ function keepSharedU(n, p) { } } -function keepShared(n, p) { - return keepSharedU(n, (function (a) { - return p(a); - })); -} - -function keepCopyU(n, p) { +function keepCopy(n, p) { if (n === undefined) { return; } @@ -578,13 +542,7 @@ function keepCopyU(n, p) { return fromSortedArrayAux(v, 0, last); } -function keepCopy(n, p) { - return keepCopyU(n, (function (x) { - return p(x); - })); -} - -function partitionCopyU(n, p) { +function partitionCopy(n, p) { if (n === undefined) { return [ undefined, @@ -606,12 +564,6 @@ function partitionCopyU(n, p) { ]; } -function partitionCopy(n, p) { - return partitionCopyU(n, (function (a) { - return p(a); - })); -} - function has(_t, x, cmp) { while(true) { let t = _t; @@ -875,7 +827,7 @@ function fromArray(xs, cmp) { if (len === 0) { return; } - let next = Belt_SortArray.strictlySortedLengthU(xs, (function (x, y) { + let next = Belt_SortArray.strictlySortedLength(xs, (function (x, y) { return cmp(x, y) < 0; })); let result; @@ -915,23 +867,15 @@ export { removeMinAuxWithRef, isEmpty, stackAllLeft, - forEachU, forEach, - reduceU, reduce, - everyU, every, - someU, some, joinShared, concatShared, - keepSharedU, keepShared, - keepCopyU, keepCopy, - partitionSharedU, partitionShared, - partitionCopyU, partitionCopy, lengthNode, size, diff --git a/belt/src/belt_internalAVLset.res b/belt/src/belt_internalAVLset.res index c48fc98..422e30b 100644 --- a/belt/src/belt_internalAVLset.res +++ b/belt/src/belt_internalAVLset.res @@ -180,40 +180,33 @@ let rec stackAllLeft = (v, s) => | Some(x) => stackAllLeft(x.left, list{x, ...s}) } -let rec forEachU = (n, f) => +let rec forEach = (n, f) => switch n { | None => () | Some(n) => - forEachU(n.left, f) + forEach(n.left, f) f(n.value) - forEachU(n.right, f) + forEach(n.right, f) } -let forEach = (n, f) => forEachU(n, a => f(a)) - -let rec reduceU = (s, accu, f) => +let rec reduce = (s, accu, f) => switch s { | None => accu - | Some(n) => reduceU(n.right, f(reduceU(n.left, accu, f), n.value), f) + | Some(n) => reduce(n.right, f(reduce(n.left, accu, f), n.value), f) } -let reduce = (s, accu, f) => reduceU(s, accu, (a, b) => f(a, b)) - -let rec everyU = (n, p) => +let rec every = (n, p) => switch n { | None => true - | Some(n) => p(n.value) && (n.left->everyU(p) && n.right->everyU(p)) + | Some(n) => p(n.value) && (n.left->every(p) && n.right->every(p)) } -let every = (n, p) => everyU(n, a => p(a)) - -let rec someU = (n, p) => +let rec some = (n, p) => switch n { | None => false - | Some(n) => p(n.value) || (someU(n.left, p) || someU(n.right, p)) + | Some(n) => p(n.value) || (some(n.left, p) || some(n.right, p)) } -let some = (n, p) => someU(n, a => p(a)) /* `addMinElement v n` and `addMaxElement v n` assume that the added v is *strictly* smaller (or bigger) than all the present elements in the tree. @@ -266,14 +259,14 @@ let concatShared = (t1, t2) => joinShared(t1, v.contents, t2r) } -let rec partitionSharedU = (n, p) => +let rec partitionShared = (n, p) => switch n { | None => (None, None) | Some(n) => let value = n.value - let (lt, lf) = partitionSharedU(n.left, p) + let (lt, lf) = partitionShared(n.left, p) let pv = p(value) - let (rt, rf) = partitionSharedU(n.right, p) + let (rt, rf) = partitionShared(n.right, p) if pv { (joinShared(lt, value, rt), concatShared(lf, rf)) } else { @@ -281,8 +274,6 @@ let rec partitionSharedU = (n, p) => } } -let partitionShared = (n, p) => partitionSharedU(n, a => p(a)) - let rec lengthNode = n => { let {left: l, right: r} = n let sizeL = switch l { @@ -448,14 +439,14 @@ let rec fromSortedArrayAux = (arr, off, len) => let fromSortedArrayUnsafe = arr => fromSortedArrayAux(arr, 0, A.length(arr)) -let rec keepSharedU = (n, p) => +let rec keepShared = (n, p) => switch n { | None => None | Some(n) => let {left: l, value: v, right: r} = n - let newL = keepSharedU(l, p) + let newL = keepShared(l, p) let pv = p(v) - let newR = keepSharedU(r, p) + let newR = keepShared(r, p) if pv { if l === newL && r === newR { Some(n) @@ -467,13 +458,12 @@ let rec keepSharedU = (n, p) => } } -let keepShared = (n, p) => keepSharedU(n, a => p(a)) /* ATT: functional methods in general can be shared with imperative methods, however, it does not apply when functional methods makes use of referential equality */ -let keepCopyU = (n, p): t<_> => +let keepCopy = (n, p): t<_> => switch n { | None => None | Some(n) => @@ -483,9 +473,7 @@ let keepCopyU = (n, p): t<_> => fromSortedArrayAux(v, 0, last) } -let keepCopy = (n, p) => keepCopyU(n, x => p(x)) - -let partitionCopyU = (n, p) => +let partitionCopy = (n, p) => switch n { | None => (None, None) | Some(n) => @@ -498,8 +486,6 @@ let partitionCopyU = (n, p) => (fromSortedArrayAux(v, 0, forwardLen), fromSortedArrayRevAux(v, backward, size - forwardLen)) } -let partitionCopy = (n, p) => partitionCopyU(n, a => p(a)) - let rec has = (t: t<_>, x, ~cmp) => switch t { | None => false @@ -736,7 +722,7 @@ let fromArray = (xs: array<_>, ~cmp) => { if len == 0 { None } else { - let next = ref(S.strictlySortedLengthU(xs, (x, y) => Belt_Id.getCmpInternal(cmp)(x, y) < 0)) + let next = ref(S.strictlySortedLength(xs, (x, y) => Belt_Id.getCmpInternal(cmp)(x, y) < 0)) let result = ref( if next.contents >= 0 { fromSortedArrayAux(xs, 0, next.contents) diff --git a/belt/src/belt_internalAVLset.resi b/belt/src/belt_internalAVLset.resi index 5068724..c4be58b 100644 --- a/belt/src/belt_internalAVLset.resi +++ b/belt/src/belt_internalAVLset.resi @@ -55,31 +55,23 @@ let isEmpty: t<'a> => bool let stackAllLeft: (t<'a>, list>) => list> -let forEachU: (t<'a>, 'a => unit) => unit let forEach: (t<'a>, 'a => unit) => unit -let reduceU: (t<'a>, 'b, ('b, 'a) => 'b) => 'b let reduce: (t<'a>, 'b, ('b, 'a) => 'b) => 'b -let everyU: (t<'a>, 'a => bool) => bool let every: (t<'a>, 'a => bool) => bool -let someU: (t<'a>, 'a => bool) => bool let some: (t<'a>, 'a => bool) => bool let joinShared: (t<'a>, 'a, t<'a>) => t<'a> let concatShared: (t<'a>, t<'a>) => t<'a> -let keepSharedU: (t<'a>, 'a => bool) => t<'a> let keepShared: (t<'a>, 'a => bool) => t<'a> -let keepCopyU: (t<'a>, 'a => bool) => t<'a> let keepCopy: (t<'a>, 'a => bool) => t<'a> -let partitionSharedU: (t<'a>, 'a => bool) => (t<'a>, t<'a>) let partitionShared: (t<'a>, 'a => bool) => (t<'a>, t<'a>) -let partitionCopyU: (t<'a>, 'a => bool) => (t<'a>, t<'a>) let partitionCopy: (t<'a>, 'a => bool) => (t<'a>, t<'a>) let lengthNode: node<'a> => int diff --git a/belt/src/belt_internalAVLtree.js b/belt/src/belt_internalAVLtree.js index f97e3b4..43e9d4b 100644 --- a/belt/src/belt_internalAVLtree.js +++ b/belt/src/belt_internalAVLtree.js @@ -244,11 +244,11 @@ function stackAllLeft(_v, _s) { }; } -function findFirstByU(n, p) { +function findFirstBy(n, p) { if (n === undefined) { return; } - let left = findFirstByU(n.l, p); + let left = findFirstBy(n.l, p); if (left !== undefined) { return left; } @@ -261,45 +261,33 @@ function findFirstByU(n, p) { d ]; } - let right = findFirstByU(n.r, p); + let right = findFirstBy(n.r, p); if (right !== undefined) { return right; } } -function findFirstBy(n, p) { - return findFirstByU(n, (function (a, b) { - return p(a, b); - })); -} - -function forEachU(_n, f) { +function forEach(_n, f) { while(true) { let n = _n; if (n === undefined) { return; } - forEachU(n.l, f); + forEach(n.l, f); f(n.k, n.v); _n = n.r; continue; }; } -function forEach(n, f) { - forEachU(n, (function (a, b) { - f(a, b); - })); -} - -function mapU(n, f) { +function map(n, f) { if (n === undefined) { return; } - let newLeft = mapU(n.l, f); + let newLeft = map(n.l, f); let newD = f(n.v); - let newRight = mapU(n.r, f); + let newRight = map(n.r, f); return { k: n.k, v: newD, @@ -309,20 +297,14 @@ function mapU(n, f) { }; } -function map(n, f) { - return mapU(n, (function (a) { - return f(a); - })); -} - -function mapWithKeyU(n, f) { +function mapWithKey(n, f) { if (n === undefined) { return; } let key = n.k; - let newLeft = mapWithKeyU(n.l, f); + let newLeft = mapWithKey(n.l, f); let newD = f(key, n.v); - let newRight = mapWithKeyU(n.r, f); + let newRight = mapWithKey(n.r, f); return { k: key, v: newD, @@ -332,13 +314,7 @@ function mapWithKeyU(n, f) { }; } -function mapWithKey(n, f) { - return mapWithKeyU(n, (function (a, b) { - return f(a, b); - })); -} - -function reduceU(_m, _accu, f) { +function reduce(_m, _accu, f) { while(true) { let accu = _accu; let m = _m; @@ -349,19 +325,13 @@ function reduceU(_m, _accu, f) { let d = m.v; let l = m.l; let r = m.r; - _accu = f(reduceU(l, accu, f), v, d); + _accu = f(reduce(l, accu, f), v, d); _m = r; continue; }; } -function reduce(m, accu, f) { - return reduceU(m, accu, (function (a, b, c) { - return f(a, b, c); - })); -} - -function everyU(_n, p) { +function every(_n, p) { while(true) { let n = _n; if (n === undefined) { @@ -370,7 +340,7 @@ function everyU(_n, p) { if (!p(n.k, n.v)) { return false; } - if (!everyU(n.l, p)) { + if (!every(n.l, p)) { return false; } _n = n.r; @@ -378,13 +348,7 @@ function everyU(_n, p) { }; } -function every(n, p) { - return everyU(n, (function (a, b) { - return p(a, b); - })); -} - -function someU(_n, p) { +function some(_n, p) { while(true) { let n = _n; if (n === undefined) { @@ -393,7 +357,7 @@ function someU(_n, p) { if (p(n.k, n.v)) { return true; } - if (someU(n.l, p)) { + if (some(n.l, p)) { return true; } _n = n.r; @@ -401,12 +365,6 @@ function someU(_n, p) { }; } -function some(n, p) { - return someU(n, (function (a, b) { - return p(a, b); - })); -} - function addMinElement(n, k, v) { if (n !== undefined) { return bal(addMinElement(n.l, k, v), n.k, n.v, n.r); @@ -474,15 +432,15 @@ function concatOrJoin(t1, v, d, t2) { } } -function keepSharedU(n, p) { +function keepShared(n, p) { if (n === undefined) { return; } let v = n.k; let d = n.v; - let newLeft = keepSharedU(n.l, p); + let newLeft = keepShared(n.l, p); let pvd = p(v, d); - let newRight = keepSharedU(n.r, p); + let newRight = keepShared(n.r, p); if (pvd) { return join(newLeft, v, d, newRight); } else { @@ -490,21 +448,15 @@ function keepSharedU(n, p) { } } -function keepShared(n, p) { - return keepSharedU(n, (function (a, b) { - return p(a, b); - })); -} - -function keepMapU(n, p) { +function keepMap(n, p) { if (n === undefined) { return; } let v = n.k; let d = n.v; - let newLeft = keepMapU(n.l, p); + let newLeft = keepMap(n.l, p); let pvd = p(v, d); - let newRight = keepMapU(n.r, p); + let newRight = keepMap(n.r, p); if (pvd !== undefined) { return join(newLeft, v, Caml_option.valFromOption(pvd), newRight); } else { @@ -512,13 +464,7 @@ function keepMapU(n, p) { } } -function keepMap(n, p) { - return keepMapU(n, (function (a, b) { - return p(a, b); - })); -} - -function partitionSharedU(n, p) { +function partitionShared(n, p) { if (n === undefined) { return [ undefined, @@ -527,11 +473,11 @@ function partitionSharedU(n, p) { } let key = n.k; let value = n.v; - let match = partitionSharedU(n.l, p); + let match = partitionShared(n.l, p); let lf = match[1]; let lt = match[0]; let pvd = p(key, value); - let match$1 = partitionSharedU(n.r, p); + let match$1 = partitionShared(n.r, p); let rf = match$1[1]; let rt = match$1[0]; if (pvd) { @@ -547,12 +493,6 @@ function partitionSharedU(n, p) { } } -function partitionShared(n, p) { - return partitionSharedU(n, (function (a, b) { - return p(a, b); - })); -} - function lengthNode(n) { let l = n.l; let r = n.r; @@ -611,7 +551,7 @@ function checkInvariantInternal(_v) { RE_EXN_ID: "Assert_failure", _1: [ "belt_internalAVLtree.res", - 457, + 439, 4 ] } @@ -800,7 +740,7 @@ function fromSortedArrayUnsafe(arr) { return fromSortedArrayAux(arr, 0, arr.length); } -function cmpU(s1, s2, kcmp, vcmp) { +function cmp(s1, s2, kcmp, vcmp) { let len1 = size(s1); let len2 = size(s2); if (len1 === len2) { @@ -836,13 +776,7 @@ function cmpU(s1, s2, kcmp, vcmp) { } } -function cmp(s1, s2, kcmp, vcmp) { - return cmpU(s1, s2, kcmp, (function (a, b) { - return vcmp(a, b); - })); -} - -function eqU(s1, s2, kcmp, veq) { +function eq(s1, s2, kcmp, veq) { let len1 = size(s1); let len2 = size(s2); if (len1 === len2) { @@ -871,12 +805,6 @@ function eqU(s1, s2, kcmp, veq) { } } -function eq(s1, s2, kcmp, veq) { - return eqU(s1, s2, kcmp, (function (a, b) { - return veq(a, b); - })); -} - function get(_n, x, cmp) { while(true) { let n = _n; @@ -1073,7 +1001,7 @@ function fromArray(xs, cmp) { if (len === 0) { return; } - let next = Belt_SortArray.strictlySortedLengthU(xs, (function (param, param$1) { + let next = Belt_SortArray.strictlySortedLength(xs, (function (param, param$1) { return cmp(param[0], param$1[0]) < 0; })); let result; @@ -1120,28 +1048,18 @@ export { removeMinAuxWithRef, isEmpty, stackAllLeft, - findFirstByU, findFirstBy, - forEachU, forEach, - mapU, map, - mapWithKeyU, mapWithKey, - reduceU, reduce, - everyU, every, - someU, some, join, concat, concatOrJoin, - keepSharedU, keepShared, - keepMapU, keepMap, - partitionSharedU, partitionShared, lengthNode, size, @@ -1154,9 +1072,7 @@ export { fromSortedArrayAux, fromSortedArrayRevAux, fromSortedArrayUnsafe, - cmpU, cmp, - eqU, eq, get, getUndefined, diff --git a/belt/src/belt_internalAVLtree.res b/belt/src/belt_internalAVLtree.res index 0a70808..e47c211 100644 --- a/belt/src/belt_internalAVLtree.res +++ b/belt/src/belt_internalAVLtree.res @@ -223,11 +223,11 @@ let rec stackAllLeft = (v, s) => | Some(x) => stackAllLeft(x.left, list{x, ...s}) } -let rec findFirstByU = (n, p) => +let rec findFirstBy = (n, p) => switch n { | None => None | Some(n) => - let left = findFirstByU(n.left, p) + let left = findFirstBy(n.left, p) if left != None { left } else { @@ -236,7 +236,7 @@ let rec findFirstByU = (n, p) => if pvd { Some(v, d) } else { - let right = findFirstByU(n.right, p) + let right = findFirstBy(n.right, p) if right != None { right } else { @@ -246,67 +246,55 @@ let rec findFirstByU = (n, p) => } } -let findFirstBy = (n, p) => findFirstByU(n, (a, b) => p(a, b)) - -let rec forEachU = (n, f) => +let rec forEach = (n, f) => switch n { | None => () | Some(n) => - forEachU(n.left, f) + forEach(n.left, f) f(n.key, n.value) - forEachU(n.right, f) + forEach(n.right, f) } -let forEach = (n, f) => forEachU(n, (a, b) => f(a, b)) - -let rec mapU = (n, f) => +let rec map = (n, f) => switch n { | None => None | Some(n) => - let newLeft = mapU(n.left, f) + let newLeft = map(n.left, f) let newD = f(n.value) - let newRight = mapU(n.right, f) + let newRight = map(n.right, f) Some({left: newLeft, key: n.key, value: newD, right: newRight, height: n.height}) } -let map = (n, f) => mapU(n, a => f(a)) - -let rec mapWithKeyU = (n, f) => +let rec mapWithKey = (n, f) => switch n { | None => None | Some(n) => let key = n.key - let newLeft = mapWithKeyU(n.left, f) + let newLeft = mapWithKey(n.left, f) let newD = f(key, n.value) - let newRight = mapWithKeyU(n.right, f) + let newRight = mapWithKey(n.right, f) Some({left: newLeft, key, value: newD, right: newRight, height: n.height}) } -let mapWithKey = (n, f) => mapWithKeyU(n, (a, b) => f(a, b)) - -let rec reduceU = (m, accu, f) => +let rec reduce = (m, accu, f) => switch m { | None => accu | Some(n) => let {left: l, key: v, value: d, right: r} = n - reduceU(r, f(reduceU(l, accu, f), v, d), f) + reduce(r, f(reduce(l, accu, f), v, d), f) } -let reduce = (m, accu, f) => reduceU(m, accu, (a, b, c) => f(a, b, c)) - -let rec everyU = (n, p) => +let rec every = (n, p) => switch n { | None => true - | Some(n) => p(n.key, n.value) && (everyU(n.left, p) && everyU(n.right, p)) + | Some(n) => p(n.key, n.value) && (every(n.left, p) && every(n.right, p)) } -let every = (n, p) => everyU(n, (a, b) => p(a, b)) -let rec someU = (n, p) => +let rec some = (n, p) => switch n { | None => false - | Some(n) => p(n.key, n.value) || (someU(n.left, p) || someU(n.right, p)) + | Some(n) => p(n.key, n.value) || (some(n.left, p) || some(n.right, p)) } -let some = (n, p) => someU(n, (a, b) => p(a, b)) /* Beware: those two functions assume that the added k is *strictly* smaller (or bigger) than all the present keys in the tree; it does not test for equality with the current min (or max) key. @@ -366,15 +354,15 @@ let concatOrJoin = (t1, v, d, t2) => | None => concat(t1, t2) } -let rec keepSharedU = (n, p) => +let rec keepShared = (n, p) => switch n { | None => None | Some(n) => /* call `p` in the expected left-to-right order */ let {key: v, value: d} = n - let newLeft = keepSharedU(n.left, p) + let newLeft = keepShared(n.left, p) let pvd = p(v, d) - let newRight = keepSharedU(n.right, p) + let newRight = keepShared(n.right, p) if pvd { join(newLeft, v, d, newRight) } else { @@ -382,34 +370,30 @@ let rec keepSharedU = (n, p) => } } -let keepShared = (n, p) => keepSharedU(n, (a, b) => p(a, b)) - -let rec keepMapU = (n, p) => +let rec keepMap = (n, p) => switch n { | None => None | Some(n) => /* call `p` in the expected left-to-right order */ let {key: v, value: d} = n - let newLeft = keepMapU(n.left, p) + let newLeft = keepMap(n.left, p) let pvd = p(v, d) - let newRight = keepMapU(n.right, p) + let newRight = keepMap(n.right, p) switch pvd { | None => concat(newLeft, newRight) | Some(d) => join(newLeft, v, d, newRight) } } -let keepMap = (n, p) => keepMapU(n, (a, b) => p(a, b)) - -let rec partitionSharedU = (n, p) => +let rec partitionShared = (n, p) => switch n { | None => (None, None) | Some(n) => let {key, value} = n /* call `p` in the expected left-to-right order */ - let (lt, lf) = partitionSharedU(n.left, p) + let (lt, lf) = partitionShared(n.left, p) let pvd = p(key, value) - let (rt, rf) = partitionSharedU(n.right, p) + let (rt, rf) = partitionShared(n.right, p) if pvd { (join(lt, key, value, rt), concat(lf, rf)) } else { @@ -417,8 +401,6 @@ let rec partitionSharedU = (n, p) => } } -let partitionShared = (n, p) => partitionSharedU(n, (a, b) => p(a, b)) - let rec lengthNode = n => { let {left: l, right: r} = n let sizeL = switch l { @@ -667,7 +649,7 @@ let rec eqAux = (e1, e2, ~kcmp, ~veq) => | (_, _) => true } -let cmpU = (s1, s2, ~kcmp, ~vcmp) => { +let cmp = (s1, s2, ~kcmp, ~vcmp) => { let (len1, len2) = (size(s1), size(s2)) if len1 == len2 { compareAux(stackAllLeft(s1, list{}), stackAllLeft(s2, list{}), ~kcmp, ~vcmp) @@ -678,9 +660,7 @@ let cmpU = (s1, s2, ~kcmp, ~vcmp) => { } } -let cmp = (s1, s2, ~kcmp, ~vcmp) => cmpU(s1, s2, ~kcmp, ~vcmp=(a, b) => vcmp(a, b)) - -let eqU = (s1, s2, ~kcmp, ~veq) => { +let eq = (s1, s2, ~kcmp, ~veq) => { let (len1, len2) = (size(s1), size(s2)) if len1 == len2 { eqAux(stackAllLeft(s1, list{}), stackAllLeft(s2, list{}), ~kcmp, ~veq) @@ -689,8 +669,6 @@ let eqU = (s1, s2, ~kcmp, ~veq) => { } } -let eq = (s1, s2, ~kcmp, ~veq) => eqU(s1, s2, ~kcmp, ~veq=(a, b) => veq(a, b)) - let rec get = (n, x, ~cmp) => switch n { | None => None @@ -910,7 +888,7 @@ let fromArray = (xs: array<_>, ~cmp) => { None } else { let next = ref( - S.strictlySortedLengthU(xs, ((x0, _), (y0, _)) => Belt_Id.getCmpInternal(cmp)(x0, y0) < 0), + S.strictlySortedLength(xs, ((x0, _), (y0, _)) => Belt_Id.getCmpInternal(cmp)(x0, y0) < 0), ) let result = ref( diff --git a/belt/src/belt_internalAVLtree.resi b/belt/src/belt_internalAVLtree.resi index 9b55a0f..31e7625 100644 --- a/belt/src/belt_internalAVLtree.resi +++ b/belt/src/belt_internalAVLtree.resi @@ -60,25 +60,18 @@ let isEmpty: t<_> => bool let stackAllLeft: (t<'a, 'b>, list>) => list> -let findFirstByU: (t<'a, 'b>, ('a, 'b) => bool) => option<('a, 'b)> let findFirstBy: (t<'a, 'b>, ('a, 'b) => bool) => option<('a, 'b)> -let forEachU: (t<'a, 'b>, ('a, 'b) => unit) => unit let forEach: (t<'a, 'b>, ('a, 'b) => unit) => unit -let mapU: (t<'c, 'a>, 'a => 'b) => t<'c, 'b> let map: (t<'c, 'a>, 'a => 'b) => t<'c, 'b> -let mapWithKeyU: (t<'a, 'b>, ('a, 'b) => 'c) => t<'a, 'c> let mapWithKey: (t<'a, 'b>, ('a, 'b) => 'c) => t<'a, 'c> -let reduceU: (t<'a, 'b>, 'c, ('c, 'a, 'b) => 'c) => 'c let reduce: (t<'a, 'b>, 'c, ('c, 'a, 'b) => 'c) => 'c -let everyU: (t<'a, 'b>, ('a, 'b) => bool) => bool let every: (t<'a, 'b>, ('a, 'b) => bool) => bool -let someU: (t<'a, 'b>, ('a, 'b) => bool) => bool let some: (t<'a, 'b>, ('a, 'b) => bool) => bool let join: (t<'a, 'b>, 'a, 'b, t<'a, 'b>) => t<'a, 'b> @@ -87,14 +80,11 @@ let concat: (t<'a, 'b>, t<'a, 'b>) => t<'a, 'b> let concatOrJoin: (t<'a, 'b>, 'a, option<'b>, t<'a, 'b>) => t<'a, 'b> -let keepSharedU: (t<'a, 'b>, ('a, 'b) => bool) => t<'a, 'b> let keepShared: (t<'a, 'b>, ('a, 'b) => bool) => t<'a, 'b> -let keepMapU: (t<'a, 'b>, ('a, 'b) => option<'c>) => t<'a, 'c> let keepMap: (t<'a, 'b>, ('a, 'b) => option<'c>) => t<'a, 'c> /* seems no sharing, could be shared with mutation */ -let partitionSharedU: (t<'a, 'b>, ('a, 'b) => bool) => (t<'a, 'b>, t<'a, 'b>) let partitionShared: (t<'a, 'b>, ('a, 'b) => bool) => (t<'a, 'b>, t<'a, 'b>) let lengthNode: node<'a, 'b> => int @@ -115,10 +105,8 @@ let fromSortedArrayAux: (array<('a, 'b)>, int, int) => t<'a, 'b> let fromSortedArrayRevAux: (array<('a, 'b)>, int, int) => t<'a, 'b> let fromSortedArrayUnsafe: array<('a, 'b)> => t<'a, 'b> -let cmpU: (t<'a, 'b>, t<'a, 'c>, ~kcmp: cmp<'a, _>, ~vcmp: ('b, 'c) => int) => int let cmp: (t<'a, 'b>, t<'a, 'c>, ~kcmp: cmp<'a, _>, ~vcmp: ('b, 'c) => int) => int -let eqU: (t<'a, 'b>, t<'a, 'c>, ~kcmp: cmp<'a, _>, ~veq: ('b, 'c) => bool) => bool let eq: (t<'a, 'b>, t<'a, 'c>, ~kcmp: cmp<'a, _>, ~veq: ('b, 'c) => bool) => bool let get: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => option<'b> diff --git a/belt/src/belt_internalBuckets.js b/belt/src/belt_internalBuckets.js index 6a22071..a6c67c5 100644 --- a/belt/src/belt_internalBuckets.js +++ b/belt/src/belt_internalBuckets.js @@ -78,19 +78,13 @@ function do_bucket_iter(f, _buckets) { }; } -function forEachU(h, f) { +function forEach(h, f) { let d = h.buckets; for(let i = 0 ,i_finish = d.length; i < i_finish; ++i){ do_bucket_iter(f, d[i]); } } -function forEach(h, f) { - forEachU(h, (function (a, b) { - return f(a, b); - })); -} - function do_bucket_fold(f, _b, _accu) { while(true) { let accu = _accu; @@ -104,7 +98,7 @@ function do_bucket_fold(f, _b, _accu) { }; } -function reduceU(h, init, f) { +function reduce(h, init, f) { let d = h.buckets; let accu = init; for(let i = 0 ,i_finish = d.length; i < i_finish; ++i){ @@ -113,14 +107,8 @@ function reduceU(h, init, f) { return accu; } -function reduce(h, init, f) { - return reduceU(h, init, (function (a, b, c) { - return f(a, b, c); - })); -} - function getMaxBucketLength(h) { - return Belt_Array.reduceU(h.buckets, 0, (function (m, b) { + return Belt_Array.reduce(h.buckets, 0, (function (m, b) { let len = bucketLength(0, b); if (m > len) { return m; @@ -132,10 +120,10 @@ function getMaxBucketLength(h) { function getBucketHistogram(h) { let mbl = getMaxBucketLength(h); - let histo = Belt_Array.makeByU(mbl + 1 | 0, (function (param) { + let histo = Belt_Array.makeBy(mbl + 1 | 0, (function (param) { return 0; })); - Belt_Array.forEachU(h.buckets, (function (b) { + Belt_Array.forEach(h.buckets, (function (b) { let l = bucketLength(0, b); histo[l] = histo[l] + 1 | 0; })); @@ -186,7 +174,7 @@ function filterMapInplaceBucket(f, h, i, _prec, _cell) { }; } -function keepMapInPlaceU(h, f) { +function keepMapInPlace(h, f) { let h_buckets = h.buckets; for(let i = 0 ,i_finish = h_buckets.length; i < i_finish; ++i){ let v = h_buckets[i]; @@ -197,12 +185,6 @@ function keepMapInPlaceU(h, f) { } } -function keepMapInPlace(h, f) { - keepMapInPlaceU(h, (function (a, b) { - return f(a, b); - })); -} - function fillArray(_i, arr, _cell) { while(true) { let cell = _cell; @@ -276,12 +258,9 @@ let C; export { C, copy, - forEachU, forEach, - reduceU, reduce, logStats, - keepMapInPlaceU, keepMapInPlace, fillArray, keysToArray, diff --git a/belt/src/belt_internalBuckets.res b/belt/src/belt_internalBuckets.res index c70b6e5..d58b455 100644 --- a/belt/src/belt_internalBuckets.res +++ b/belt/src/belt_internalBuckets.res @@ -84,22 +84,20 @@ let rec do_bucket_iter = (~f, buckets) => do_bucket_iter(~f, cell.next) } -let forEachU = (h, f) => { +let forEach = (h, f) => { let d = h.C.buckets for i in 0 to A.length(d) - 1 { do_bucket_iter(~f, A.getUnsafe(d, i)) } } -let forEach = (h, f) => forEachU(h, (a, b) => f(a, b)) - let rec do_bucket_fold = (~f, b, accu) => switch C.toOpt(b) { | None => accu | Some(cell) => do_bucket_fold(~f, cell.next, f(accu, cell.key, cell.value)) } -let reduceU = (h, init, f) => { +let reduce = (h, init, f) => { let d = h.C.buckets let accu = ref(init) for i in 0 to A.length(d) - 1 { @@ -108,18 +106,16 @@ let reduceU = (h, init, f) => { accu.contents } -let reduce = (h, init, f) => reduceU(h, init, (a, b, c) => f(a, b, c)) - let getMaxBucketLength = h => - A.reduceU(h.C.buckets, 0, (m, b) => { + A.reduce(h.C.buckets, 0, (m, b) => { let len = bucketLength(0, b) Pervasives.max(m, len) }) let getBucketHistogram = h => { let mbl = getMaxBucketLength(h) - let histo = A.makeByU(mbl + 1, _ => 0) - A.forEachU(h.C.buckets, b => { + let histo = A.makeBy(mbl + 1, _ => 0) + A.forEach(h.C.buckets, b => { let l = bucketLength(0, b) A.setUnsafe(histo, l, A.getUnsafe(histo, l) + 1) }) @@ -164,7 +160,7 @@ let rec filterMapInplaceBucket = (f, h, i, prec, cell) => { } } -let keepMapInPlaceU = (h, f) => { +let keepMapInPlace = (h, f) => { let h_buckets = h.C.buckets for i in 0 to A.length(h_buckets) - 1 { let v = A.getUnsafe(h_buckets, i) @@ -175,8 +171,6 @@ let keepMapInPlaceU = (h, f) => { } } -let keepMapInPlace = (h, f) => keepMapInPlaceU(h, (a, b) => f(a, b)) - let rec fillArray = (i, arr, cell) => { A.setUnsafe(arr, i, (cell.key, cell.value)) switch C.toOpt(cell.next) { diff --git a/belt/src/belt_internalBuckets.resi b/belt/src/belt_internalBuckets.resi index 3190490..750d488 100644 --- a/belt/src/belt_internalBuckets.resi +++ b/belt/src/belt_internalBuckets.resi @@ -33,15 +33,12 @@ and t<'hash, 'eq, 'a, 'b> = C.container<'hash, 'eq, bucket<'a, 'b>> let copy: t<'hash, 'eq, 'a, 'b> => t<'hash, 'eq, 'a, 'b> -let forEachU: (t<_, _, 'a, 'b>, ('a, 'b) => 'c) => unit let forEach: (t<_, _, 'a, 'b>, ('a, 'b) => 'c) => unit -let reduceU: (t<_, _, 'a, 'b>, 'c, ('c, 'a, 'b) => 'c) => 'c let reduce: (t<_, _, 'a, 'b>, 'c, ('c, 'a, 'b) => 'c) => 'c let logStats: t<_> => unit -let keepMapInPlaceU: (t<_, _, 'a, 'b>, ('a, 'b) => option<'b>) => unit let keepMapInPlace: (t<_, _, 'a, 'b>, ('a, 'b) => option<'b>) => unit let fillArray: (int, array<('a, 'b)>, bucket<'a, 'b>) => int diff --git a/belt/src/belt_internalMapInt.js b/belt/src/belt_internalMapInt.js index e055358..223f8bd 100644 --- a/belt/src/belt_internalMapInt.js +++ b/belt/src/belt_internalMapInt.js @@ -184,7 +184,7 @@ function split(x, n) { } } -function mergeU(s1, s2, f) { +function merge(s1, s2, f) { if (s1 !== undefined) { if (s1.h >= ( s2 !== undefined ? s2.h : 0 @@ -194,7 +194,7 @@ function mergeU(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(mergeU(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), mergeU(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -205,13 +205,7 @@ function mergeU(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(mergeU(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), mergeU(match$1[2], r2, f)); -} - -function merge(s1, s2, f) { - return mergeU(s1, s2, (function (a, b, c) { - return f(a, b, c); - })); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -240,11 +234,11 @@ function compareAux(_e1, _e2, vcmp) { }; } -function cmpU(s1, s2, cmp) { +function cmp(s1, s2, cmp$1) { let len1 = Belt_internalAVLtree.size(s1); let len2 = Belt_internalAVLtree.size(s2); if (len1 === len2) { - return compareAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), cmp); + return compareAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), cmp$1); } else if (len1 < len2) { return -1; } else { @@ -252,12 +246,6 @@ function cmpU(s1, s2, cmp) { } } -function cmp(s1, s2, f) { - return cmpU(s1, s2, (function (a, b) { - return f(a, b); - })); -} - function eqAux(_e1, _e2, eq) { while(true) { let e2 = _e2; @@ -279,22 +267,16 @@ function eqAux(_e1, _e2, eq) { }; } -function eqU(s1, s2, eq) { +function eq(s1, s2, eq$1) { let len1 = Belt_internalAVLtree.size(s1); let len2 = Belt_internalAVLtree.size(s2); if (len1 === len2) { - return eqAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), eq); + return eqAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), eq$1); } else { return false; } } -function eq(s1, s2, f) { - return eqU(s1, s2, (function (a, b) { - return f(a, b); - })); -} - function addMutate(t, x, data) { if (t === undefined) { return Belt_internalAVLtree.singleton(x, data); @@ -321,7 +303,7 @@ function fromArray(xs) { if (len === 0) { return; } - let next = Belt_SortArray.strictlySortedLengthU(xs, (function (param, param$1) { + let next = Belt_SortArray.strictlySortedLength(xs, (function (param, param$1) { return param[0] < param$1[0]; })); let result; @@ -344,6 +326,12 @@ let A; let S; +let cmpU = cmp; + +let eqU = eq; + +let mergeU = merge; + export { N, A, @@ -357,15 +345,15 @@ export { remove, splitAux, split, - mergeU, merge, compareAux, - cmpU, cmp, eqAux, - eqU, eq, addMutate, fromArray, + cmpU, + eqU, + mergeU, } /* No side effect */ diff --git a/belt/src/belt_internalMapInt.res b/belt/src/belt_internalMapInt.res index 72c2149..f60cbd9 100644 --- a/belt/src/belt_internalMapInt.res +++ b/belt/src/belt_internalMapInt.res @@ -168,7 +168,7 @@ let split = (x: key, n) => | Some(n) => splitAux(x, n) } -let rec mergeU = (s1, s2, f) => +let rec merge = (s1, s2, f) => switch (s1, s2) { | (None, None) => None | (Some(n) /* (Node (l1, v1, d1, r1, h1), _) */, _) @@ -179,16 +179,14 @@ let rec mergeU = (s1, s2, f) => } => let {N.left: l1, key: v1, value: d1, right: r1} = n let (l2, d2, r2) = split(v1, s2) - N.concatOrJoin(mergeU(l1, l2, f), v1, f(v1, Some(d1), d2), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v1, f(v1, Some(d1), d2), merge(r1, r2, f)) | (_, Some(n)) /* Node (l2, v2, d2, r2, h2) */ => let {N.left: l2, key: v2, value: d2, right: r2} = n let (l1, d1, r1) = split(v2, s1) - N.concatOrJoin(mergeU(l1, l2, f), v2, f(v2, d1, Some(d2)), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v2, f(v2, d1, Some(d2)), merge(r1, r2, f)) | _ => assert(false) } -let merge = (s1, s2, f) => mergeU(s1, s2, (a, b, c) => f(a, b, c)) - let rec compareAux = (e1, e2, vcmp) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -206,7 +204,7 @@ let rec compareAux = (e1, e2, vcmp) => | (_, _) => 0 } -let cmpU = (s1, s2, cmp) => { +let cmp = (s1, s2, cmp) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { compareAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), cmp) @@ -217,8 +215,6 @@ let cmpU = (s1, s2, cmp) => { } } -let cmp = (s1, s2, f) => cmpU(s1, s2, (a, b) => f(a, b)) - let rec eqAux = (e1, e2, eq) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -230,7 +226,7 @@ let rec eqAux = (e1, e2, eq) => | (_, _) => true } /* end */ -let eqU = (s1, s2, eq) => { +let eq = (s1, s2, eq) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { eqAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), eq) @@ -239,8 +235,6 @@ let eqU = (s1, s2, eq) => { } } -let eq = (s1, s2, f) => eqU(s1, s2, (a, b) => f(a, b)) - let rec addMutate = (t: t<_>, x, data): t<_> => switch t { | None => N.singleton(x, data) @@ -269,7 +263,7 @@ let fromArray = (xs: array<(key, _)>) => { if len == 0 { None } else { - let next = ref(S.strictlySortedLengthU(xs, ((x0, _), (y0, _)) => x0 < y0)) + let next = ref(S.strictlySortedLength(xs, ((x0, _), (y0, _)) => x0 < y0)) let result = ref( if next.contents >= 0 { @@ -286,3 +280,7 @@ let fromArray = (xs: array<(key, _)>) => { result.contents } } + +let cmpU = cmp +let eqU = eq +let mergeU = merge diff --git a/belt/src/belt_internalMapString.js b/belt/src/belt_internalMapString.js index da6164b..04c95f5 100644 --- a/belt/src/belt_internalMapString.js +++ b/belt/src/belt_internalMapString.js @@ -184,7 +184,7 @@ function split(x, n) { } } -function mergeU(s1, s2, f) { +function merge(s1, s2, f) { if (s1 !== undefined) { if (s1.h >= ( s2 !== undefined ? s2.h : 0 @@ -194,7 +194,7 @@ function mergeU(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(mergeU(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), mergeU(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -205,13 +205,7 @@ function mergeU(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(mergeU(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), mergeU(match$1[2], r2, f)); -} - -function merge(s1, s2, f) { - return mergeU(s1, s2, (function (a, b, c) { - return f(a, b, c); - })); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -240,11 +234,11 @@ function compareAux(_e1, _e2, vcmp) { }; } -function cmpU(s1, s2, cmp) { +function cmp(s1, s2, cmp$1) { let len1 = Belt_internalAVLtree.size(s1); let len2 = Belt_internalAVLtree.size(s2); if (len1 === len2) { - return compareAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), cmp); + return compareAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), cmp$1); } else if (len1 < len2) { return -1; } else { @@ -252,12 +246,6 @@ function cmpU(s1, s2, cmp) { } } -function cmp(s1, s2, f) { - return cmpU(s1, s2, (function (a, b) { - return f(a, b); - })); -} - function eqAux(_e1, _e2, eq) { while(true) { let e2 = _e2; @@ -279,22 +267,16 @@ function eqAux(_e1, _e2, eq) { }; } -function eqU(s1, s2, eq) { +function eq(s1, s2, eq$1) { let len1 = Belt_internalAVLtree.size(s1); let len2 = Belt_internalAVLtree.size(s2); if (len1 === len2) { - return eqAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), eq); + return eqAux(Belt_internalAVLtree.stackAllLeft(s1, /* [] */0), Belt_internalAVLtree.stackAllLeft(s2, /* [] */0), eq$1); } else { return false; } } -function eq(s1, s2, f) { - return eqU(s1, s2, (function (a, b) { - return f(a, b); - })); -} - function addMutate(t, x, data) { if (t === undefined) { return Belt_internalAVLtree.singleton(x, data); @@ -321,7 +303,7 @@ function fromArray(xs) { if (len === 0) { return; } - let next = Belt_SortArray.strictlySortedLengthU(xs, (function (param, param$1) { + let next = Belt_SortArray.strictlySortedLength(xs, (function (param, param$1) { return param[0] < param$1[0]; })); let result; @@ -344,6 +326,12 @@ let A; let S; +let cmpU = cmp; + +let eqU = eq; + +let mergeU = merge; + export { N, A, @@ -357,15 +345,15 @@ export { remove, splitAux, split, - mergeU, merge, compareAux, - cmpU, cmp, eqAux, - eqU, eq, addMutate, fromArray, + cmpU, + eqU, + mergeU, } /* No side effect */ diff --git a/belt/src/belt_internalMapString.res b/belt/src/belt_internalMapString.res index fdc2d31..4ac6c00 100644 --- a/belt/src/belt_internalMapString.res +++ b/belt/src/belt_internalMapString.res @@ -168,7 +168,7 @@ let split = (x: key, n) => | Some(n) => splitAux(x, n) } -let rec mergeU = (s1, s2, f) => +let rec merge = (s1, s2, f) => switch (s1, s2) { | (None, None) => None | (Some(n) /* (Node (l1, v1, d1, r1, h1), _) */, _) @@ -179,16 +179,14 @@ let rec mergeU = (s1, s2, f) => } => let {N.left: l1, key: v1, value: d1, right: r1} = n let (l2, d2, r2) = split(v1, s2) - N.concatOrJoin(mergeU(l1, l2, f), v1, f(v1, Some(d1), d2), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v1, f(v1, Some(d1), d2), merge(r1, r2, f)) | (_, Some(n)) /* Node (l2, v2, d2, r2, h2) */ => let {N.left: l2, key: v2, value: d2, right: r2} = n let (l1, d1, r1) = split(v2, s1) - N.concatOrJoin(mergeU(l1, l2, f), v2, f(v2, d1, Some(d2)), mergeU(r1, r2, f)) + N.concatOrJoin(merge(l1, l2, f), v2, f(v2, d1, Some(d2)), merge(r1, r2, f)) | _ => assert(false) } -let merge = (s1, s2, f) => mergeU(s1, s2, (a, b, c) => f(a, b, c)) - let rec compareAux = (e1, e2, vcmp) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -206,7 +204,7 @@ let rec compareAux = (e1, e2, vcmp) => | (_, _) => 0 } -let cmpU = (s1, s2, cmp) => { +let cmp = (s1, s2, cmp) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { compareAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), cmp) @@ -217,8 +215,6 @@ let cmpU = (s1, s2, cmp) => { } } -let cmp = (s1, s2, f) => cmpU(s1, s2, (a, b) => f(a, b)) - let rec eqAux = (e1, e2, eq) => switch (e1, e2) { | (list{h1, ...t1}, list{h2, ...t2}) => @@ -230,7 +226,7 @@ let rec eqAux = (e1, e2, eq) => | (_, _) => true } /* end */ -let eqU = (s1, s2, eq) => { +let eq = (s1, s2, eq) => { let (len1, len2) = (N.size(s1), N.size(s2)) if len1 == len2 { eqAux(N.stackAllLeft(s1, list{}), N.stackAllLeft(s2, list{}), eq) @@ -239,8 +235,6 @@ let eqU = (s1, s2, eq) => { } } -let eq = (s1, s2, f) => eqU(s1, s2, (a, b) => f(a, b)) - let rec addMutate = (t: t<_>, x, data): t<_> => switch t { | None => N.singleton(x, data) @@ -269,7 +263,7 @@ let fromArray = (xs: array<(key, _)>) => { if len == 0 { None } else { - let next = ref(S.strictlySortedLengthU(xs, ((x0, _), (y0, _)) => x0 < y0)) + let next = ref(S.strictlySortedLength(xs, ((x0, _), (y0, _)) => x0 < y0)) let result = ref( if next.contents >= 0 { @@ -286,3 +280,7 @@ let fromArray = (xs: array<(key, _)>) => { result.contents } } + +let cmpU = cmp +let eqU = eq +let mergeU = merge diff --git a/belt/src/belt_internalSetBuckets.js b/belt/src/belt_internalSetBuckets.js index e4b289d..3c6b215 100644 --- a/belt/src/belt_internalSetBuckets.js +++ b/belt/src/belt_internalSetBuckets.js @@ -75,19 +75,13 @@ function doBucketIter(f, _buckets) { }; } -function forEachU(h, f) { +function forEach(h, f) { let d = h.buckets; for(let i = 0 ,i_finish = d.length; i < i_finish; ++i){ doBucketIter(f, d[i]); } } -function forEach(h, f) { - forEachU(h, (function (a) { - f(a); - })); -} - function fillArray(_i, arr, _cell) { while(true) { let cell = _cell; @@ -130,7 +124,7 @@ function doBucketFold(f, _b, _accu) { }; } -function reduceU(h, init, f) { +function reduce(h, init, f) { let d = h.buckets; let accu = init; for(let i = 0 ,i_finish = d.length; i < i_finish; ++i){ @@ -139,14 +133,8 @@ function reduceU(h, init, f) { return accu; } -function reduce(h, init, f) { - return reduceU(h, init, (function (a, b) { - return f(a, b); - })); -} - function getMaxBucketLength(h) { - return Belt_Array.reduceU(h.buckets, 0, (function (m, b) { + return Belt_Array.reduce(h.buckets, 0, (function (m, b) { let len = bucketLength(0, b); if (m > len) { return m; @@ -158,10 +146,10 @@ function getMaxBucketLength(h) { function getBucketHistogram(h) { let mbl = getMaxBucketLength(h); - let histo = Belt_Array.makeByU(mbl + 1 | 0, (function (param) { + let histo = Belt_Array.makeBy(mbl + 1 | 0, (function (param) { return 0; })); - Belt_Array.forEachU(h.buckets, (function (b) { + Belt_Array.forEach(h.buckets, (function (b) { let l = bucketLength(0, b); histo[l] = histo[l] + 1 | 0; })); @@ -182,11 +170,9 @@ let C; export { C, copy, - forEachU, forEach, fillArray, toArray, - reduceU, reduce, logStats, getBucketHistogram, diff --git a/belt/src/belt_internalSetBuckets.res b/belt/src/belt_internalSetBuckets.res index e1f3602..4e50678 100644 --- a/belt/src/belt_internalSetBuckets.res +++ b/belt/src/belt_internalSetBuckets.res @@ -87,15 +87,13 @@ let rec doBucketIter = (~f, buckets) => doBucketIter(~f, cell.next) } -let forEachU = (h, f) => { +let forEach = (h, f) => { let d = h.C.buckets for i in 0 to A.length(d) - 1 { doBucketIter(~f, A.getUnsafe(d, i)) } } -let forEach = (h, f) => forEachU(h, a => f(a)) - let rec fillArray = (i, arr, cell) => { A.setUnsafe(arr, i, cell.key) switch C.toOpt(cell.next) { @@ -124,7 +122,7 @@ let rec doBucketFold = (~f, b, accu) => | Some(cell) => doBucketFold(~f, cell.next, f(accu, cell.key)) } -let reduceU = (h, init, f) => { +let reduce = (h, init, f) => { let d = h.C.buckets let accu = ref(init) for i in 0 to A.length(d) - 1 { @@ -133,18 +131,16 @@ let reduceU = (h, init, f) => { accu.contents } -let reduce = (h, init, f) => reduceU(h, init, (a, b) => f(a, b)) - let getMaxBucketLength = h => - A.reduceU(h.C.buckets, 0, (m, b) => { + A.reduce(h.C.buckets, 0, (m, b) => { let len = bucketLength(0, b) Pervasives.max(m, len) }) let getBucketHistogram = h => { let mbl = getMaxBucketLength(h) - let histo = A.makeByU(mbl + 1, _ => 0) - A.forEachU(h.C.buckets, b => { + let histo = A.makeBy(mbl + 1, _ => 0) + A.forEach(h.C.buckets, b => { let l = bucketLength(0, b) A.setUnsafe(histo, l, A.getUnsafe(histo, l) + 1) }) diff --git a/belt/src/belt_internalSetBuckets.resi b/belt/src/belt_internalSetBuckets.resi index 8a3e255..4167a03 100644 --- a/belt/src/belt_internalSetBuckets.resi +++ b/belt/src/belt_internalSetBuckets.resi @@ -32,13 +32,11 @@ and t<'hash, 'eq, 'a> = C.container<'hash, 'eq, bucket<'a>> let copy: t<'hash, 'eq, 'a> => t<'hash, 'eq, 'a> -let forEachU: (t<'hash, 'eq, 'a>, 'a => unit) => unit let forEach: (t<'hash, 'eq, 'a>, 'a => unit) => unit let fillArray: (int, array<'a>, bucket<'a>) => int let toArray: t<_, _, 'a> => array<'a> -let reduceU: (t<_, _, 'a>, 'b, ('b, 'a) => 'b) => 'b let reduce: (t<_, _, 'a>, 'b, ('b, 'a) => 'b) => 'b let logStats: t<_> => unit