diff --git a/packages/squiggle-lang/src/rescript/utility/E.res b/packages/squiggle-lang/src/rescript/utility/E.res index 6d2a2ce2..71c4c1e4 100644 --- a/packages/squiggle-lang/src/rescript/utility/E.res +++ b/packages/squiggle-lang/src/rescript/utility/E.res @@ -1,5 +1,4 @@ open Rationale.Function.Infix - module FloatFloatMap = { module Id = Belt.Id.MakeComparable({ type t = float @@ -87,6 +86,11 @@ module O = { let max = compare(\">") } +module O2 = { + let default = (a, b) => O.default(b, a) + let toExn = (a, b) => O.toExn(b, a) +} + /* Functions */ module F = { let apply = (a, e) => a |> e @@ -324,7 +328,7 @@ module A = { | r => Some(r) } ) - let filter = (o, e) => Js.Array.filter(o, e) + let filter = Js.Array.filter let joinWith = Js.Array.joinWith module O = { @@ -438,6 +442,11 @@ module A = { } } +module A2 = { + let fmap = (a, b) => Array.map(b, a) + let joinWith = (a, b) => A.joinWith(b, a) +} + module JsArray = { let concatSomes = (optionals: Js.Array.t>): Js.Array.t<'a> => optionals diff --git a/packages/squiggle-lang/src/rescript/utility/Sparklines.res b/packages/squiggle-lang/src/rescript/utility/Sparklines.res index cc07860f..12d509fa 100644 --- a/packages/squiggle-lang/src/rescript/utility/Sparklines.res +++ b/packages/squiggle-lang/src/rescript/utility/Sparklines.res @@ -8,19 +8,19 @@ let ticks = [`▁`, `▂`, `▃`, `▄`, `▅`, `▆`, `▇`, `█`] let _ticksLength = E.A.length(ticks) let _heightToTickIndex = (maximum: float, v: float) => { - let v = Js.Math.ceil_int(v /. maximum *. Belt.Int.toFloat(_ticksLength)) - 1 - min(v, 0) + let suggestedTickIndex = Js.Math.ceil_int(v /. maximum *. Belt.Int.toFloat(_ticksLength)) - 1 + max(suggestedTickIndex, 0) } let create = (relativeHeights: array, ~maximum=?, ()) => { if E.A.length(relativeHeights) === 0 { "" } else { - let maximum = maximum |> E.O.default(E.A.max(relativeHeights) |> E.O.toExn("")) + let maximum = maximum->E.O2.default(E.A.max(relativeHeights)->E.O2.toExn("")) relativeHeights - |> E.A.fmap(_heightToTickIndex(maximum)) - |> E.A.fmap(r => E.A.get(ticks, r) |> E.O.toExn("")) - |> E.A.joinWith("") + ->E.A2.fmap(_heightToTickIndex(maximum)) + ->E.A2.fmap(r => E.A.get(ticks, r)->E.O2.toExn("")) + ->E.A2.joinWith("") } }