From 674213360caa7facfa1cf92e0f35f15df08e5c31 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 19 Sep 2022 22:00:01 +0400 Subject: [PATCH] trim lodash usage, remove unused module --- .../squiggle-lang/__tests__/Lodash_test.res | 20 ------------------- .../squiggle-lang/src/js/SqPointSetDist.ts | 4 ++-- .../Distributions/SampleSetDist/KdeLibrary.js | 13 ++++++------ .../src/rescript/Utility/Lodash.res | 5 ----- packages/squiggle-lang/tsconfig.json | 3 ++- 5 files changed, 11 insertions(+), 34 deletions(-) delete mode 100644 packages/squiggle-lang/__tests__/Lodash_test.res delete mode 100644 packages/squiggle-lang/src/rescript/Utility/Lodash.res diff --git a/packages/squiggle-lang/__tests__/Lodash_test.res b/packages/squiggle-lang/__tests__/Lodash_test.res deleted file mode 100644 index f0782019..00000000 --- a/packages/squiggle-lang/__tests__/Lodash_test.res +++ /dev/null @@ -1,20 +0,0 @@ -open Jest -open Expect - -let makeTest = (~only=false, str, item1, item2) => - only - ? Only.test(str, () => expect(item1)->toEqual(item2)) - : test(str, () => expect(item1)->toEqual(item2)) - -describe("Lodash", () => - describe("Lodash", () => { - makeTest("min", Lodash.min([1, 3, 4]), 1) - makeTest("max", Lodash.max([1, 3, 4]), 4) - makeTest("uniq", Lodash.uniq([1, 3, 4, 4]), [1, 3, 4]) - makeTest( - "countBy", - Lodash.countBy([1, 3, 4, 4], r => r), - Js.Dict.fromArray([("1", 1), ("3", 1), ("4", 2)]), - ) - }) -) diff --git a/packages/squiggle-lang/src/js/SqPointSetDist.ts b/packages/squiggle-lang/src/js/SqPointSetDist.ts index 524c9319..19a6b178 100644 --- a/packages/squiggle-lang/src/js/SqPointSetDist.ts +++ b/packages/squiggle-lang/src/js/SqPointSetDist.ts @@ -1,4 +1,4 @@ -import * as _ from "lodash"; +import zipWith from "lodash/zipWith"; import { wrapDistribution } from "./SqDistribution"; import * as RSPointSetDist from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.gen"; import { pointSetDistributionTag as Tag } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag"; @@ -16,7 +16,7 @@ const shapePoints = ( ): SqPoint[] => { let xs = x.xyShape.xs; let ys = x.xyShape.ys; - return _.zipWith(xs, ys, (x, y) => ({ x, y })); + return zipWith(xs, ys, (x, y) => ({ x, y })); }; export const wrapPointSetDist = (value: T) => { diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js index 9cc75b39..e9592745 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/KdeLibrary.js @@ -1,5 +1,6 @@ const pdfast = require("pdfast"); -const _ = require("lodash"); +const filter = require("lodash/filter"); +const isFinite = require("lodash/isFinite"); const samplesToContinuousPdf = ( samples, @@ -8,12 +9,12 @@ const samplesToContinuousPdf = ( min = false, max = false ) => { - let _samples = _.filter(samples, _.isFinite); - if (_.isFinite(min)) { - _samples = _.filter(_samples, (r) => r > min); + let _samples = filter(samples, isFinite); + if (isFinite(min)) { + _samples = filter(_samples, (r) => r > min); } - if (_.isFinite(max)) { - _samples = _.filter(_samples, (r) => r < max); + if (isFinite(max)) { + _samples = filter(_samples, (r) => r < max); } // The pdf that's created from this function is not a pdf but a pmf. y values diff --git a/packages/squiggle-lang/src/rescript/Utility/Lodash.res b/packages/squiggle-lang/src/rescript/Utility/Lodash.res deleted file mode 100644 index d4359408..00000000 --- a/packages/squiggle-lang/src/rescript/Utility/Lodash.res +++ /dev/null @@ -1,5 +0,0 @@ -@module("lodash") external min: array<'a> => 'a = "min" -@module("lodash") external max: array<'a> => 'a = "max" -@module("lodash") external uniq: array<'a> => array<'a> = "uniq" -@module("lodash") -external countBy: (array<'a>, 'a => 'b) => Js.Dict.t = "countBy" diff --git a/packages/squiggle-lang/tsconfig.json b/packages/squiggle-lang/tsconfig.json index b9433729..92350eb1 100644 --- a/packages/squiggle-lang/tsconfig.json +++ b/packages/squiggle-lang/tsconfig.json @@ -12,7 +12,8 @@ "declarationDir": "./dist", "declaration": true, "composite": true, - "target": "ES6" + "target": "ES6", + "esModuleInterop": true }, "include": ["src/**/*"], "exclude": ["node_modules", "**/*.spec.ts", "webpack.config.js"]