diff --git a/.changeset/modern-tips-sell.md b/.changeset/modern-tips-sell.md new file mode 100644 index 00000000..0debd380 --- /dev/null +++ b/.changeset/modern-tips-sell.md @@ -0,0 +1,5 @@ +--- +"@tsplus/stdlib": patch +--- + +add Differ data type diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 11b8c02e..b87c6195 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -31,6 +31,7 @@ module.exports = { // The TypeScript configuration of dprint // See also https://dprint.dev/plugins/typescript/config/, "indentWidth": 2, + "lineWidth": 100, "semiColons": "asi", "quoteStyle": "alwaysDouble", "trailingCommas": "never", diff --git a/package.json b/package.json index 238b4bf9..d41613f6 100644 --- a/package.json +++ b/package.json @@ -35,12 +35,12 @@ "@babel/core": "^7.18.10", "@babel/plugin-transform-modules-commonjs": "^7.18.6", "@changesets/changelog-github": "^0.4.6", - "@changesets/cli": "^2.24.1", + "@changesets/cli": "^2.24.2", "@effect-ts/build-utils": "0.40.3", "@effect-ts/core": "^0.60.2", "@repo-tooling/eslint-plugin-dprint": "^0.0.4", "@tsplus/installer": "0.0.132", - "@types/node": "^18.6.3", + "@types/node": "^18.6.4", "@types/rimraf": "^3.0.2", "@typescript-eslint/eslint-plugin": "^5.32.0", "@typescript-eslint/parser": "^5.32.0", diff --git a/packages/stdlib/_src/collections/Chunk.ts b/packages/stdlib/_src/collections/Chunk.ts index 2370fb94..54acb61d 100644 --- a/packages/stdlib/_src/collections/Chunk.ts +++ b/packages/stdlib/_src/collections/Chunk.ts @@ -1,103 +1,6 @@ // codegen:start {preset: barrel, include: ./Chunk/*.ts, prefix: "@tsplus/stdlib/collections"} -export * from "@tsplus/stdlib/collections/Chunk/append" -export * from "@tsplus/stdlib/collections/Chunk/buckets" -export * from "@tsplus/stdlib/collections/Chunk/builder" -export * from "@tsplus/stdlib/collections/Chunk/collect" -export * from "@tsplus/stdlib/collections/Chunk/collectWhile" -export * from "@tsplus/stdlib/collections/Chunk/collectWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/compact" -export * from "@tsplus/stdlib/collections/Chunk/compactF" -export * from "@tsplus/stdlib/collections/Chunk/compactWithIndexF" -export * from "@tsplus/stdlib/collections/Chunk/concat" -export * from "@tsplus/stdlib/collections/Chunk/dedupe" export * from "@tsplus/stdlib/collections/Chunk/definition" -export * from "@tsplus/stdlib/collections/Chunk/difference" -export * from "@tsplus/stdlib/collections/Chunk/drop" -export * from "@tsplus/stdlib/collections/Chunk/dropRight" -export * from "@tsplus/stdlib/collections/Chunk/dropWhile" -export * from "@tsplus/stdlib/collections/Chunk/elem" -export * from "@tsplus/stdlib/collections/Chunk/empty" -export * from "@tsplus/stdlib/collections/Chunk/equals" -export * from "@tsplus/stdlib/collections/Chunk/exists" -export * from "@tsplus/stdlib/collections/Chunk/extend" -export * from "@tsplus/stdlib/collections/Chunk/fill" -export * from "@tsplus/stdlib/collections/Chunk/filter" -export * from "@tsplus/stdlib/collections/Chunk/filterWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/find" -export * from "@tsplus/stdlib/collections/Chunk/findIndex" -export * from "@tsplus/stdlib/collections/Chunk/findLast" -export * from "@tsplus/stdlib/collections/Chunk/findLastIndex" -export * from "@tsplus/stdlib/collections/Chunk/flatMap" -export * from "@tsplus/stdlib/collections/Chunk/flatten" -export * from "@tsplus/stdlib/collections/Chunk/forAll" -export * from "@tsplus/stdlib/collections/Chunk/forAny" -export * from "@tsplus/stdlib/collections/Chunk/forEach" -export * from "@tsplus/stdlib/collections/Chunk/forEachF" -export * from "@tsplus/stdlib/collections/Chunk/forEachWithIndexF" -export * from "@tsplus/stdlib/collections/Chunk/get" -export * from "@tsplus/stdlib/collections/Chunk/getAssociative" -export * from "@tsplus/stdlib/collections/Chunk/getAssociativeIdentity" -export * from "@tsplus/stdlib/collections/Chunk/getEquivalence" -export * from "@tsplus/stdlib/collections/Chunk/getOrd" -export * from "@tsplus/stdlib/collections/Chunk/getShow" -export * from "@tsplus/stdlib/collections/Chunk/grouped" -export * from "@tsplus/stdlib/collections/Chunk/head" -export * from "@tsplus/stdlib/collections/Chunk/indexWhere" -export * from "@tsplus/stdlib/collections/Chunk/indexWhereFrom" export * from "@tsplus/stdlib/collections/Chunk/instances" -export * from "@tsplus/stdlib/collections/Chunk/intersection" -export * from "@tsplus/stdlib/collections/Chunk/isEmpty" -export * from "@tsplus/stdlib/collections/Chunk/isNonEmpty" -export * from "@tsplus/stdlib/collections/Chunk/join" -export * from "@tsplus/stdlib/collections/Chunk/last" -export * from "@tsplus/stdlib/collections/Chunk/make" -export * from "@tsplus/stdlib/collections/Chunk/makeBy" -export * from "@tsplus/stdlib/collections/Chunk/map" -export * from "@tsplus/stdlib/collections/Chunk/mapAccum" -export * from "@tsplus/stdlib/collections/Chunk/mapWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/materialize" -export * from "@tsplus/stdlib/collections/Chunk/partition" -export * from "@tsplus/stdlib/collections/Chunk/partitionMap" -export * from "@tsplus/stdlib/collections/Chunk/partitionMapWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/partitionWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/prepend" -export * from "@tsplus/stdlib/collections/Chunk/range" -export * from "@tsplus/stdlib/collections/Chunk/reduce" -export * from "@tsplus/stdlib/collections/Chunk/reduceRight" -export * from "@tsplus/stdlib/collections/Chunk/reduceRightWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/reduceWhile" -export * from "@tsplus/stdlib/collections/Chunk/reduceWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/reverse" -export * from "@tsplus/stdlib/collections/Chunk/reverseBuckets" -export * from "@tsplus/stdlib/collections/Chunk/separate" -export * from "@tsplus/stdlib/collections/Chunk/separateF" -export * from "@tsplus/stdlib/collections/Chunk/separateWithIndexF" -export * from "@tsplus/stdlib/collections/Chunk/single" -export * from "@tsplus/stdlib/collections/Chunk/size" -export * from "@tsplus/stdlib/collections/Chunk/sort" -export * from "@tsplus/stdlib/collections/Chunk/sortBy" -export * from "@tsplus/stdlib/collections/Chunk/split" -export * from "@tsplus/stdlib/collections/Chunk/splitAt" -export * from "@tsplus/stdlib/collections/Chunk/splitWhere" -export * from "@tsplus/stdlib/collections/Chunk/tail" -export * from "@tsplus/stdlib/collections/Chunk/take" -export * from "@tsplus/stdlib/collections/Chunk/takeRight" -export * from "@tsplus/stdlib/collections/Chunk/takeWhile" -export * from "@tsplus/stdlib/collections/Chunk/toArrayLike" -export * from "@tsplus/stdlib/collections/Chunk/toCollection" -export * from "@tsplus/stdlib/collections/Chunk/unfold" -export * from "@tsplus/stdlib/collections/Chunk/union" -export * from "@tsplus/stdlib/collections/Chunk/uniq" -export * from "@tsplus/stdlib/collections/Chunk/unit" -export * from "@tsplus/stdlib/collections/Chunk/unsafeGet" -export * from "@tsplus/stdlib/collections/Chunk/unsafeHead" -export * from "@tsplus/stdlib/collections/Chunk/unsafeLast" -export * from "@tsplus/stdlib/collections/Chunk/unsafeTail" -export * from "@tsplus/stdlib/collections/Chunk/unzip" -export * from "@tsplus/stdlib/collections/Chunk/zip" -export * from "@tsplus/stdlib/collections/Chunk/zipAll" -export * from "@tsplus/stdlib/collections/Chunk/zipAllWith" -export * from "@tsplus/stdlib/collections/Chunk/zipWith" -export * from "@tsplus/stdlib/collections/Chunk/zipWithIndex" -export * from "@tsplus/stdlib/collections/Chunk/zipWithIndexOffset" +export * from "@tsplus/stdlib/collections/Chunk/operations" +export * from "@tsplus/stdlib/collections/Chunk/patch" // codegen:end diff --git a/packages/stdlib/_src/collections/Chunk/operations.ts b/packages/stdlib/_src/collections/Chunk/operations.ts new file mode 100644 index 00000000..ffcf7ed4 --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/operations.ts @@ -0,0 +1,101 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/Chunk"} +export * from "@tsplus/stdlib/collections/Chunk/operations/append" +export * from "@tsplus/stdlib/collections/Chunk/operations/buckets" +export * from "@tsplus/stdlib/collections/Chunk/operations/builder" +export * from "@tsplus/stdlib/collections/Chunk/operations/collect" +export * from "@tsplus/stdlib/collections/Chunk/operations/collectWhile" +export * from "@tsplus/stdlib/collections/Chunk/operations/collectWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/compact" +export * from "@tsplus/stdlib/collections/Chunk/operations/compactF" +export * from "@tsplus/stdlib/collections/Chunk/operations/compactWithIndexF" +export * from "@tsplus/stdlib/collections/Chunk/operations/concat" +export * from "@tsplus/stdlib/collections/Chunk/operations/dedupe" +export * from "@tsplus/stdlib/collections/Chunk/operations/difference" +export * from "@tsplus/stdlib/collections/Chunk/operations/drop" +export * from "@tsplus/stdlib/collections/Chunk/operations/dropRight" +export * from "@tsplus/stdlib/collections/Chunk/operations/dropWhile" +export * from "@tsplus/stdlib/collections/Chunk/operations/elem" +export * from "@tsplus/stdlib/collections/Chunk/operations/empty" +export * from "@tsplus/stdlib/collections/Chunk/operations/equals" +export * from "@tsplus/stdlib/collections/Chunk/operations/exists" +export * from "@tsplus/stdlib/collections/Chunk/operations/extend" +export * from "@tsplus/stdlib/collections/Chunk/operations/fill" +export * from "@tsplus/stdlib/collections/Chunk/operations/filter" +export * from "@tsplus/stdlib/collections/Chunk/operations/filterWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/find" +export * from "@tsplus/stdlib/collections/Chunk/operations/findIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/findLast" +export * from "@tsplus/stdlib/collections/Chunk/operations/findLastIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/flatMap" +export * from "@tsplus/stdlib/collections/Chunk/operations/flatten" +export * from "@tsplus/stdlib/collections/Chunk/operations/forAll" +export * from "@tsplus/stdlib/collections/Chunk/operations/forAny" +export * from "@tsplus/stdlib/collections/Chunk/operations/forEach" +export * from "@tsplus/stdlib/collections/Chunk/operations/forEachF" +export * from "@tsplus/stdlib/collections/Chunk/operations/forEachWithIndexF" +export * from "@tsplus/stdlib/collections/Chunk/operations/get" +export * from "@tsplus/stdlib/collections/Chunk/operations/getAssociative" +export * from "@tsplus/stdlib/collections/Chunk/operations/getAssociativeIdentity" +export * from "@tsplus/stdlib/collections/Chunk/operations/getEquivalence" +export * from "@tsplus/stdlib/collections/Chunk/operations/getOrd" +export * from "@tsplus/stdlib/collections/Chunk/operations/getShow" +export * from "@tsplus/stdlib/collections/Chunk/operations/grouped" +export * from "@tsplus/stdlib/collections/Chunk/operations/head" +export * from "@tsplus/stdlib/collections/Chunk/operations/indexWhere" +export * from "@tsplus/stdlib/collections/Chunk/operations/indexWhereFrom" +export * from "@tsplus/stdlib/collections/Chunk/operations/intersection" +export * from "@tsplus/stdlib/collections/Chunk/operations/isEmpty" +export * from "@tsplus/stdlib/collections/Chunk/operations/isNonEmpty" +export * from "@tsplus/stdlib/collections/Chunk/operations/join" +export * from "@tsplus/stdlib/collections/Chunk/operations/last" +export * from "@tsplus/stdlib/collections/Chunk/operations/make" +export * from "@tsplus/stdlib/collections/Chunk/operations/makeBy" +export * from "@tsplus/stdlib/collections/Chunk/operations/map" +export * from "@tsplus/stdlib/collections/Chunk/operations/mapAccum" +export * from "@tsplus/stdlib/collections/Chunk/operations/mapWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/materialize" +export * from "@tsplus/stdlib/collections/Chunk/operations/partition" +export * from "@tsplus/stdlib/collections/Chunk/operations/partitionMap" +export * from "@tsplus/stdlib/collections/Chunk/operations/partitionMapWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/partitionWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/prepend" +export * from "@tsplus/stdlib/collections/Chunk/operations/range" +export * from "@tsplus/stdlib/collections/Chunk/operations/reduce" +export * from "@tsplus/stdlib/collections/Chunk/operations/reduceRight" +export * from "@tsplus/stdlib/collections/Chunk/operations/reduceRightWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/reduceWhile" +export * from "@tsplus/stdlib/collections/Chunk/operations/reduceWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/reverse" +export * from "@tsplus/stdlib/collections/Chunk/operations/reverseBuckets" +export * from "@tsplus/stdlib/collections/Chunk/operations/separate" +export * from "@tsplus/stdlib/collections/Chunk/operations/separateF" +export * from "@tsplus/stdlib/collections/Chunk/operations/separateWithIndexF" +export * from "@tsplus/stdlib/collections/Chunk/operations/single" +export * from "@tsplus/stdlib/collections/Chunk/operations/size" +export * from "@tsplus/stdlib/collections/Chunk/operations/sort" +export * from "@tsplus/stdlib/collections/Chunk/operations/sortBy" +export * from "@tsplus/stdlib/collections/Chunk/operations/split" +export * from "@tsplus/stdlib/collections/Chunk/operations/splitAt" +export * from "@tsplus/stdlib/collections/Chunk/operations/splitWhere" +export * from "@tsplus/stdlib/collections/Chunk/operations/tail" +export * from "@tsplus/stdlib/collections/Chunk/operations/take" +export * from "@tsplus/stdlib/collections/Chunk/operations/takeRight" +export * from "@tsplus/stdlib/collections/Chunk/operations/takeWhile" +export * from "@tsplus/stdlib/collections/Chunk/operations/toArrayLike" +export * from "@tsplus/stdlib/collections/Chunk/operations/toCollection" +export * from "@tsplus/stdlib/collections/Chunk/operations/unfold" +export * from "@tsplus/stdlib/collections/Chunk/operations/union" +export * from "@tsplus/stdlib/collections/Chunk/operations/uniq" +export * from "@tsplus/stdlib/collections/Chunk/operations/unit" +export * from "@tsplus/stdlib/collections/Chunk/operations/unsafeGet" +export * from "@tsplus/stdlib/collections/Chunk/operations/unsafeHead" +export * from "@tsplus/stdlib/collections/Chunk/operations/unsafeLast" +export * from "@tsplus/stdlib/collections/Chunk/operations/unsafeTail" +export * from "@tsplus/stdlib/collections/Chunk/operations/unzip" +export * from "@tsplus/stdlib/collections/Chunk/operations/zip" +export * from "@tsplus/stdlib/collections/Chunk/operations/zipAll" +export * from "@tsplus/stdlib/collections/Chunk/operations/zipAllWith" +export * from "@tsplus/stdlib/collections/Chunk/operations/zipWith" +export * from "@tsplus/stdlib/collections/Chunk/operations/zipWithIndex" +export * from "@tsplus/stdlib/collections/Chunk/operations/zipWithIndexOffset" +// codegen:end diff --git a/packages/stdlib/_src/collections/Chunk/append.ts b/packages/stdlib/_src/collections/Chunk/operations/append.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/append.ts rename to packages/stdlib/_src/collections/Chunk/operations/append.ts diff --git a/packages/stdlib/_src/collections/Chunk/buckets.ts b/packages/stdlib/_src/collections/Chunk/operations/buckets.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/buckets.ts rename to packages/stdlib/_src/collections/Chunk/operations/buckets.ts diff --git a/packages/stdlib/_src/collections/Chunk/builder.ts b/packages/stdlib/_src/collections/Chunk/operations/builder.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/builder.ts rename to packages/stdlib/_src/collections/Chunk/operations/builder.ts diff --git a/packages/stdlib/_src/collections/Chunk/collect.ts b/packages/stdlib/_src/collections/Chunk/operations/collect.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/collect.ts rename to packages/stdlib/_src/collections/Chunk/operations/collect.ts diff --git a/packages/stdlib/_src/collections/Chunk/collectWhile.ts b/packages/stdlib/_src/collections/Chunk/operations/collectWhile.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/collectWhile.ts rename to packages/stdlib/_src/collections/Chunk/operations/collectWhile.ts diff --git a/packages/stdlib/_src/collections/Chunk/collectWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/collectWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/collectWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/collectWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/compact.ts b/packages/stdlib/_src/collections/Chunk/operations/compact.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/compact.ts rename to packages/stdlib/_src/collections/Chunk/operations/compact.ts diff --git a/packages/stdlib/_src/collections/Chunk/compactF.ts b/packages/stdlib/_src/collections/Chunk/operations/compactF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/compactF.ts rename to packages/stdlib/_src/collections/Chunk/operations/compactF.ts diff --git a/packages/stdlib/_src/collections/Chunk/compactWithIndexF.ts b/packages/stdlib/_src/collections/Chunk/operations/compactWithIndexF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/compactWithIndexF.ts rename to packages/stdlib/_src/collections/Chunk/operations/compactWithIndexF.ts diff --git a/packages/stdlib/_src/collections/Chunk/concat.ts b/packages/stdlib/_src/collections/Chunk/operations/concat.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/concat.ts rename to packages/stdlib/_src/collections/Chunk/operations/concat.ts diff --git a/packages/stdlib/_src/collections/Chunk/dedupe.ts b/packages/stdlib/_src/collections/Chunk/operations/dedupe.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/dedupe.ts rename to packages/stdlib/_src/collections/Chunk/operations/dedupe.ts diff --git a/packages/stdlib/_src/collections/Chunk/difference.ts b/packages/stdlib/_src/collections/Chunk/operations/difference.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/difference.ts rename to packages/stdlib/_src/collections/Chunk/operations/difference.ts diff --git a/packages/stdlib/_src/collections/Chunk/drop.ts b/packages/stdlib/_src/collections/Chunk/operations/drop.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/drop.ts rename to packages/stdlib/_src/collections/Chunk/operations/drop.ts diff --git a/packages/stdlib/_src/collections/Chunk/dropRight.ts b/packages/stdlib/_src/collections/Chunk/operations/dropRight.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/dropRight.ts rename to packages/stdlib/_src/collections/Chunk/operations/dropRight.ts diff --git a/packages/stdlib/_src/collections/Chunk/dropWhile.ts b/packages/stdlib/_src/collections/Chunk/operations/dropWhile.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/dropWhile.ts rename to packages/stdlib/_src/collections/Chunk/operations/dropWhile.ts diff --git a/packages/stdlib/_src/collections/Chunk/elem.ts b/packages/stdlib/_src/collections/Chunk/operations/elem.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/elem.ts rename to packages/stdlib/_src/collections/Chunk/operations/elem.ts diff --git a/packages/stdlib/_src/collections/Chunk/empty.ts b/packages/stdlib/_src/collections/Chunk/operations/empty.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/empty.ts rename to packages/stdlib/_src/collections/Chunk/operations/empty.ts diff --git a/packages/stdlib/_src/collections/Chunk/equals.ts b/packages/stdlib/_src/collections/Chunk/operations/equals.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/equals.ts rename to packages/stdlib/_src/collections/Chunk/operations/equals.ts diff --git a/packages/stdlib/_src/collections/Chunk/exists.ts b/packages/stdlib/_src/collections/Chunk/operations/exists.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/exists.ts rename to packages/stdlib/_src/collections/Chunk/operations/exists.ts diff --git a/packages/stdlib/_src/collections/Chunk/extend.ts b/packages/stdlib/_src/collections/Chunk/operations/extend.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/extend.ts rename to packages/stdlib/_src/collections/Chunk/operations/extend.ts diff --git a/packages/stdlib/_src/collections/Chunk/fill.ts b/packages/stdlib/_src/collections/Chunk/operations/fill.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/fill.ts rename to packages/stdlib/_src/collections/Chunk/operations/fill.ts diff --git a/packages/stdlib/_src/collections/Chunk/filter.ts b/packages/stdlib/_src/collections/Chunk/operations/filter.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/filter.ts rename to packages/stdlib/_src/collections/Chunk/operations/filter.ts diff --git a/packages/stdlib/_src/collections/Chunk/filterWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/filterWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/filterWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/filterWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/find.ts b/packages/stdlib/_src/collections/Chunk/operations/find.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/find.ts rename to packages/stdlib/_src/collections/Chunk/operations/find.ts diff --git a/packages/stdlib/_src/collections/Chunk/findIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/findIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/findIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/findIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/findLast.ts b/packages/stdlib/_src/collections/Chunk/operations/findLast.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/findLast.ts rename to packages/stdlib/_src/collections/Chunk/operations/findLast.ts diff --git a/packages/stdlib/_src/collections/Chunk/findLastIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/findLastIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/findLastIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/findLastIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/flatMap.ts b/packages/stdlib/_src/collections/Chunk/operations/flatMap.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/flatMap.ts rename to packages/stdlib/_src/collections/Chunk/operations/flatMap.ts diff --git a/packages/stdlib/_src/collections/Chunk/flatten.ts b/packages/stdlib/_src/collections/Chunk/operations/flatten.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/flatten.ts rename to packages/stdlib/_src/collections/Chunk/operations/flatten.ts diff --git a/packages/stdlib/_src/collections/Chunk/forAll.ts b/packages/stdlib/_src/collections/Chunk/operations/forAll.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/forAll.ts rename to packages/stdlib/_src/collections/Chunk/operations/forAll.ts diff --git a/packages/stdlib/_src/collections/Chunk/forAny.ts b/packages/stdlib/_src/collections/Chunk/operations/forAny.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/forAny.ts rename to packages/stdlib/_src/collections/Chunk/operations/forAny.ts diff --git a/packages/stdlib/_src/collections/Chunk/forEach.ts b/packages/stdlib/_src/collections/Chunk/operations/forEach.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/forEach.ts rename to packages/stdlib/_src/collections/Chunk/operations/forEach.ts diff --git a/packages/stdlib/_src/collections/Chunk/forEachF.ts b/packages/stdlib/_src/collections/Chunk/operations/forEachF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/forEachF.ts rename to packages/stdlib/_src/collections/Chunk/operations/forEachF.ts diff --git a/packages/stdlib/_src/collections/Chunk/forEachWithIndexF.ts b/packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/forEachWithIndexF.ts rename to packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts diff --git a/packages/stdlib/_src/collections/Chunk/get.ts b/packages/stdlib/_src/collections/Chunk/operations/get.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/get.ts rename to packages/stdlib/_src/collections/Chunk/operations/get.ts diff --git a/packages/stdlib/_src/collections/Chunk/getAssociative.ts b/packages/stdlib/_src/collections/Chunk/operations/getAssociative.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/getAssociative.ts rename to packages/stdlib/_src/collections/Chunk/operations/getAssociative.ts diff --git a/packages/stdlib/_src/collections/Chunk/getAssociativeIdentity.ts b/packages/stdlib/_src/collections/Chunk/operations/getAssociativeIdentity.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/getAssociativeIdentity.ts rename to packages/stdlib/_src/collections/Chunk/operations/getAssociativeIdentity.ts diff --git a/packages/stdlib/_src/collections/Chunk/getEquivalence.ts b/packages/stdlib/_src/collections/Chunk/operations/getEquivalence.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/getEquivalence.ts rename to packages/stdlib/_src/collections/Chunk/operations/getEquivalence.ts diff --git a/packages/stdlib/_src/collections/Chunk/getOrd.ts b/packages/stdlib/_src/collections/Chunk/operations/getOrd.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/getOrd.ts rename to packages/stdlib/_src/collections/Chunk/operations/getOrd.ts diff --git a/packages/stdlib/_src/collections/Chunk/getShow.ts b/packages/stdlib/_src/collections/Chunk/operations/getShow.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/getShow.ts rename to packages/stdlib/_src/collections/Chunk/operations/getShow.ts diff --git a/packages/stdlib/_src/collections/Chunk/grouped.ts b/packages/stdlib/_src/collections/Chunk/operations/grouped.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/grouped.ts rename to packages/stdlib/_src/collections/Chunk/operations/grouped.ts diff --git a/packages/stdlib/_src/collections/Chunk/head.ts b/packages/stdlib/_src/collections/Chunk/operations/head.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/head.ts rename to packages/stdlib/_src/collections/Chunk/operations/head.ts diff --git a/packages/stdlib/_src/collections/Chunk/indexWhere.ts b/packages/stdlib/_src/collections/Chunk/operations/indexWhere.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/indexWhere.ts rename to packages/stdlib/_src/collections/Chunk/operations/indexWhere.ts diff --git a/packages/stdlib/_src/collections/Chunk/indexWhereFrom.ts b/packages/stdlib/_src/collections/Chunk/operations/indexWhereFrom.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/indexWhereFrom.ts rename to packages/stdlib/_src/collections/Chunk/operations/indexWhereFrom.ts diff --git a/packages/stdlib/_src/collections/Chunk/intersection.ts b/packages/stdlib/_src/collections/Chunk/operations/intersection.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/intersection.ts rename to packages/stdlib/_src/collections/Chunk/operations/intersection.ts diff --git a/packages/stdlib/_src/collections/Chunk/isEmpty.ts b/packages/stdlib/_src/collections/Chunk/operations/isEmpty.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/isEmpty.ts rename to packages/stdlib/_src/collections/Chunk/operations/isEmpty.ts diff --git a/packages/stdlib/_src/collections/Chunk/isNonEmpty.ts b/packages/stdlib/_src/collections/Chunk/operations/isNonEmpty.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/isNonEmpty.ts rename to packages/stdlib/_src/collections/Chunk/operations/isNonEmpty.ts diff --git a/packages/stdlib/_src/collections/Chunk/join.ts b/packages/stdlib/_src/collections/Chunk/operations/join.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/join.ts rename to packages/stdlib/_src/collections/Chunk/operations/join.ts diff --git a/packages/stdlib/_src/collections/Chunk/last.ts b/packages/stdlib/_src/collections/Chunk/operations/last.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/last.ts rename to packages/stdlib/_src/collections/Chunk/operations/last.ts diff --git a/packages/stdlib/_src/collections/Chunk/make.ts b/packages/stdlib/_src/collections/Chunk/operations/make.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/make.ts rename to packages/stdlib/_src/collections/Chunk/operations/make.ts diff --git a/packages/stdlib/_src/collections/Chunk/makeBy.ts b/packages/stdlib/_src/collections/Chunk/operations/makeBy.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/makeBy.ts rename to packages/stdlib/_src/collections/Chunk/operations/makeBy.ts diff --git a/packages/stdlib/_src/collections/Chunk/map.ts b/packages/stdlib/_src/collections/Chunk/operations/map.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/map.ts rename to packages/stdlib/_src/collections/Chunk/operations/map.ts diff --git a/packages/stdlib/_src/collections/Chunk/mapAccum.ts b/packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/mapAccum.ts rename to packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts diff --git a/packages/stdlib/_src/collections/Chunk/mapWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/mapWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/mapWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/mapWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/materialize.ts b/packages/stdlib/_src/collections/Chunk/operations/materialize.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/materialize.ts rename to packages/stdlib/_src/collections/Chunk/operations/materialize.ts diff --git a/packages/stdlib/_src/collections/Chunk/partition.ts b/packages/stdlib/_src/collections/Chunk/operations/partition.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/partition.ts rename to packages/stdlib/_src/collections/Chunk/operations/partition.ts diff --git a/packages/stdlib/_src/collections/Chunk/partitionMap.ts b/packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/partitionMap.ts rename to packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts diff --git a/packages/stdlib/_src/collections/Chunk/partitionMapWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/partitionMapWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/partitionWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/partitionWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/partitionWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/partitionWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/prepend.ts b/packages/stdlib/_src/collections/Chunk/operations/prepend.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/prepend.ts rename to packages/stdlib/_src/collections/Chunk/operations/prepend.ts diff --git a/packages/stdlib/_src/collections/Chunk/range.ts b/packages/stdlib/_src/collections/Chunk/operations/range.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/range.ts rename to packages/stdlib/_src/collections/Chunk/operations/range.ts diff --git a/packages/stdlib/_src/collections/Chunk/reduce.ts b/packages/stdlib/_src/collections/Chunk/operations/reduce.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reduce.ts rename to packages/stdlib/_src/collections/Chunk/operations/reduce.ts diff --git a/packages/stdlib/_src/collections/Chunk/reduceRight.ts b/packages/stdlib/_src/collections/Chunk/operations/reduceRight.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reduceRight.ts rename to packages/stdlib/_src/collections/Chunk/operations/reduceRight.ts diff --git a/packages/stdlib/_src/collections/Chunk/reduceRightWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/reduceRightWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reduceRightWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/reduceRightWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/reduceWhile.ts b/packages/stdlib/_src/collections/Chunk/operations/reduceWhile.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reduceWhile.ts rename to packages/stdlib/_src/collections/Chunk/operations/reduceWhile.ts diff --git a/packages/stdlib/_src/collections/Chunk/reduceWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/reduceWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reduceWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/reduceWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/reverse.ts b/packages/stdlib/_src/collections/Chunk/operations/reverse.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reverse.ts rename to packages/stdlib/_src/collections/Chunk/operations/reverse.ts diff --git a/packages/stdlib/_src/collections/Chunk/reverseBuckets.ts b/packages/stdlib/_src/collections/Chunk/operations/reverseBuckets.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/reverseBuckets.ts rename to packages/stdlib/_src/collections/Chunk/operations/reverseBuckets.ts diff --git a/packages/stdlib/_src/collections/Chunk/separate.ts b/packages/stdlib/_src/collections/Chunk/operations/separate.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/separate.ts rename to packages/stdlib/_src/collections/Chunk/operations/separate.ts diff --git a/packages/stdlib/_src/collections/Chunk/separateF.ts b/packages/stdlib/_src/collections/Chunk/operations/separateF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/separateF.ts rename to packages/stdlib/_src/collections/Chunk/operations/separateF.ts diff --git a/packages/stdlib/_src/collections/Chunk/separateWithIndexF.ts b/packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/separateWithIndexF.ts rename to packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts diff --git a/packages/stdlib/_src/collections/Chunk/single.ts b/packages/stdlib/_src/collections/Chunk/operations/single.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/single.ts rename to packages/stdlib/_src/collections/Chunk/operations/single.ts diff --git a/packages/stdlib/_src/collections/Chunk/size.ts b/packages/stdlib/_src/collections/Chunk/operations/size.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/size.ts rename to packages/stdlib/_src/collections/Chunk/operations/size.ts diff --git a/packages/stdlib/_src/collections/Chunk/sort.ts b/packages/stdlib/_src/collections/Chunk/operations/sort.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/sort.ts rename to packages/stdlib/_src/collections/Chunk/operations/sort.ts diff --git a/packages/stdlib/_src/collections/Chunk/sortBy.ts b/packages/stdlib/_src/collections/Chunk/operations/sortBy.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/sortBy.ts rename to packages/stdlib/_src/collections/Chunk/operations/sortBy.ts diff --git a/packages/stdlib/_src/collections/Chunk/split.ts b/packages/stdlib/_src/collections/Chunk/operations/split.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/split.ts rename to packages/stdlib/_src/collections/Chunk/operations/split.ts diff --git a/packages/stdlib/_src/collections/Chunk/splitAt.ts b/packages/stdlib/_src/collections/Chunk/operations/splitAt.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/splitAt.ts rename to packages/stdlib/_src/collections/Chunk/operations/splitAt.ts diff --git a/packages/stdlib/_src/collections/Chunk/splitWhere.ts b/packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/splitWhere.ts rename to packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts diff --git a/packages/stdlib/_src/collections/Chunk/tail.ts b/packages/stdlib/_src/collections/Chunk/operations/tail.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/tail.ts rename to packages/stdlib/_src/collections/Chunk/operations/tail.ts diff --git a/packages/stdlib/_src/collections/Chunk/take.ts b/packages/stdlib/_src/collections/Chunk/operations/take.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/take.ts rename to packages/stdlib/_src/collections/Chunk/operations/take.ts diff --git a/packages/stdlib/_src/collections/Chunk/takeRight.ts b/packages/stdlib/_src/collections/Chunk/operations/takeRight.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/takeRight.ts rename to packages/stdlib/_src/collections/Chunk/operations/takeRight.ts diff --git a/packages/stdlib/_src/collections/Chunk/takeWhile.ts b/packages/stdlib/_src/collections/Chunk/operations/takeWhile.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/takeWhile.ts rename to packages/stdlib/_src/collections/Chunk/operations/takeWhile.ts diff --git a/packages/stdlib/_src/collections/Chunk/toArrayLike.ts b/packages/stdlib/_src/collections/Chunk/operations/toArrayLike.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/toArrayLike.ts rename to packages/stdlib/_src/collections/Chunk/operations/toArrayLike.ts diff --git a/packages/stdlib/_src/collections/Chunk/toCollection.ts b/packages/stdlib/_src/collections/Chunk/operations/toCollection.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/toCollection.ts rename to packages/stdlib/_src/collections/Chunk/operations/toCollection.ts diff --git a/packages/stdlib/_src/collections/Chunk/unfold.ts b/packages/stdlib/_src/collections/Chunk/operations/unfold.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unfold.ts rename to packages/stdlib/_src/collections/Chunk/operations/unfold.ts diff --git a/packages/stdlib/_src/collections/Chunk/union.ts b/packages/stdlib/_src/collections/Chunk/operations/union.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/union.ts rename to packages/stdlib/_src/collections/Chunk/operations/union.ts diff --git a/packages/stdlib/_src/collections/Chunk/uniq.ts b/packages/stdlib/_src/collections/Chunk/operations/uniq.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/uniq.ts rename to packages/stdlib/_src/collections/Chunk/operations/uniq.ts diff --git a/packages/stdlib/_src/collections/Chunk/unit.ts b/packages/stdlib/_src/collections/Chunk/operations/unit.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unit.ts rename to packages/stdlib/_src/collections/Chunk/operations/unit.ts diff --git a/packages/stdlib/_src/collections/Chunk/unsafeGet.ts b/packages/stdlib/_src/collections/Chunk/operations/unsafeGet.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unsafeGet.ts rename to packages/stdlib/_src/collections/Chunk/operations/unsafeGet.ts diff --git a/packages/stdlib/_src/collections/Chunk/unsafeHead.ts b/packages/stdlib/_src/collections/Chunk/operations/unsafeHead.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unsafeHead.ts rename to packages/stdlib/_src/collections/Chunk/operations/unsafeHead.ts diff --git a/packages/stdlib/_src/collections/Chunk/unsafeLast.ts b/packages/stdlib/_src/collections/Chunk/operations/unsafeLast.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unsafeLast.ts rename to packages/stdlib/_src/collections/Chunk/operations/unsafeLast.ts diff --git a/packages/stdlib/_src/collections/Chunk/unsafeTail.ts b/packages/stdlib/_src/collections/Chunk/operations/unsafeTail.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unsafeTail.ts rename to packages/stdlib/_src/collections/Chunk/operations/unsafeTail.ts diff --git a/packages/stdlib/_src/collections/Chunk/unzip.ts b/packages/stdlib/_src/collections/Chunk/operations/unzip.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/unzip.ts rename to packages/stdlib/_src/collections/Chunk/operations/unzip.ts diff --git a/packages/stdlib/_src/collections/Chunk/zip.ts b/packages/stdlib/_src/collections/Chunk/operations/zip.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zip.ts rename to packages/stdlib/_src/collections/Chunk/operations/zip.ts diff --git a/packages/stdlib/_src/collections/Chunk/zipAll.ts b/packages/stdlib/_src/collections/Chunk/operations/zipAll.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zipAll.ts rename to packages/stdlib/_src/collections/Chunk/operations/zipAll.ts diff --git a/packages/stdlib/_src/collections/Chunk/zipAllWith.ts b/packages/stdlib/_src/collections/Chunk/operations/zipAllWith.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zipAllWith.ts rename to packages/stdlib/_src/collections/Chunk/operations/zipAllWith.ts diff --git a/packages/stdlib/_src/collections/Chunk/zipWith.ts b/packages/stdlib/_src/collections/Chunk/operations/zipWith.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zipWith.ts rename to packages/stdlib/_src/collections/Chunk/operations/zipWith.ts diff --git a/packages/stdlib/_src/collections/Chunk/zipWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zipWithIndex.ts rename to packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts diff --git a/packages/stdlib/_src/collections/Chunk/zipWithIndexOffset.ts b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts similarity index 100% rename from packages/stdlib/_src/collections/Chunk/zipWithIndexOffset.ts rename to packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts diff --git a/packages/stdlib/_src/collections/Chunk/patch.ts b/packages/stdlib/_src/collections/Chunk/patch.ts new file mode 100644 index 00000000..f251023b --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch.ts @@ -0,0 +1,4 @@ +// codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/Chunk"} +export * from "@tsplus/stdlib/collections/Chunk/patch/definition" +export * from "@tsplus/stdlib/collections/Chunk/patch/operations" +// codegen:end diff --git a/packages/stdlib/_src/collections/Chunk/patch/definition.ts b/packages/stdlib/_src/collections/Chunk/patch/definition.ts new file mode 100644 index 00000000..62fe5ce8 --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/definition.ts @@ -0,0 +1,102 @@ +export const ChunkPatchSym = Symbol.for("@Differ.Chunk.Patch") +export type ChunkPatchSym = typeof ChunkPatchSym + +export const ChunkPatchValueSym = Symbol.for("@Differ.Chunk.Patch.Value") +export type ChunkPatchValueSym = typeof ChunkPatchValueSym + +export const ChunkPatchPatchSym = Symbol.for("@Differ.Chunk.Patch.Patch") +export type ChunkPatchPatchSym = typeof ChunkPatchPatchSym + +/** + * A patch which describes updates to a chunk of values. + * + * @tsplus type Differ.Chunk.Patch + */ +export interface ChunkPatch { + readonly [ChunkPatchSym]: ChunkPatchSym + readonly [ChunkPatchValueSym]: (_: Value) => Value + readonly [ChunkPatchPatchSym]: (_: Patch) => Patch +} + +/** + * @tsplus type Differ.Chunk.Patch.Ops + */ +export interface ChunkPatchOps { + readonly $: ChunkPatchAspects +} +/** + * @tsplus static Differ.Ops Chunk + */ +export const ChunkPatch: ChunkPatchOps = { + $: {} +} + +/** + * @tsplus type Differ.Chunk.Patch.Aspects + */ +export interface ChunkPatchAspects {} + +/** + * @tsplus unify Differ.Chunk.Patch + */ +export function unifyChunkPatch>(self: X): ChunkPatch< + [X] extends [{ [ChunkPatchValueSym]: (_: infer Value) => infer Value }] ? Value : never, + [X] extends [{ [ChunkPatchPatchSym]: (_: infer Patch) => infer Patch }] ? Patch : never +> { + return self +} + +export abstract class BaseChunkPatch implements ChunkPatch { + readonly [ChunkPatchSym]: ChunkPatchSym = ChunkPatchSym + readonly [ChunkPatchValueSym]!: (_: Value) => Value + readonly [ChunkPatchPatchSym]!: (_: Patch) => Patch +} + +export class AppendChunkPatch extends BaseChunkPatch { + readonly _tag = "Append" + constructor(readonly values: Chunk) { + super() + } +} + +export class SliceChunkPatch extends BaseChunkPatch { + readonly _tag = "Slice" + constructor(readonly from: number, readonly until: number) { + super() + } +} + +export class UpdateChunkPatch extends BaseChunkPatch { + readonly _tag = "Update" + constructor(readonly index: number, readonly patch: Patch) { + super() + } +} + +export class AndThenChunkPatch extends BaseChunkPatch { + readonly _tag = "AndThen" + constructor(readonly first: ChunkPatch, readonly second: ChunkPatch) { + super() + } +} + +export class EmptyChunkPatch extends BaseChunkPatch { + readonly _tag = "Empty" +} + +export type ChunkPatchInstruction = + | AppendChunkPatch + | SliceChunkPatch + | UpdateChunkPatch + | AndThenChunkPatch + | EmptyChunkPatch + +/** + * @tsplus macro identity + */ +export function chunkPatchInstruction( + self: ChunkPatch +): ChunkPatchInstruction { + // @ts-expect-error + return self +} diff --git a/packages/stdlib/_src/collections/Chunk/patch/operations.ts b/packages/stdlib/_src/collections/Chunk/patch/operations.ts new file mode 100644 index 00000000..636ea689 --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/operations.ts @@ -0,0 +1,6 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/Chunk/patch"} +export * from "@tsplus/stdlib/collections/Chunk/patch/operations/apply" +export * from "@tsplus/stdlib/collections/Chunk/patch/operations/combine" +export * from "@tsplus/stdlib/collections/Chunk/patch/operations/diff" +export * from "@tsplus/stdlib/collections/Chunk/patch/operations/emptyPatch" +// codegen:end diff --git a/packages/stdlib/_src/collections/Chunk/patch/operations/apply.ts b/packages/stdlib/_src/collections/Chunk/patch/operations/apply.ts new file mode 100644 index 00000000..49cd03d3 --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/operations/apply.ts @@ -0,0 +1,52 @@ +import { chunkPatchInstruction } from "@tsplus/stdlib/collections/Chunk/patch/definition" + +/** + * Applies a chunk patch to a chunk of values to produce a new chunk of + * values which represents the original chunk of values updated with the + * changes described by this patch. + * + * @tsplus static Differ.Chunk.Patch.Aspects apply + * @tsplus pipeable Differ.Chunk.Patch apply + */ +export function apply(oldValue: Chunk, differ: Differ) { + return (self: Differ.Chunk.Patch): Chunk => + applyLoop(differ, oldValue, List(self)) +} + +/** + * @tsplus tailRec + */ +function applyLoop( + differ: Differ, + chunk: Chunk, + patches: List> +): Chunk { + if (patches.isNil()) { + return chunk + } + const patch = chunkPatchInstruction(patches.head) + const nextPatches = patches.tail + switch (patch._tag) { + case "Append": { + return applyLoop(differ, chunk.concat(patch.values), nextPatches) + } + case "AndThen": { + return applyLoop(differ, chunk, nextPatches.prepend(patch.second).prepend(patch.first)) + } + case "Empty": { + return applyLoop(differ, chunk, nextPatches) + } + case "Slice": { + return applyLoop( + differ, + Chunk.from(chunk.toArray.slice(patch.from, patch.until)), + nextPatches + ) + } + case "Update": { + const array = chunk.toArray + array[patch.index] = differ.patch(patch.patch, array[patch.index]!) + return applyLoop(differ, Chunk.from(array), nextPatches) + } + } +} diff --git a/packages/stdlib/_src/collections/Chunk/patch/operations/combine.ts b/packages/stdlib/_src/collections/Chunk/patch/operations/combine.ts new file mode 100644 index 00000000..7b90527c --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/operations/combine.ts @@ -0,0 +1,13 @@ +import { AndThenChunkPatch } from "@tsplus/stdlib/collections/Chunk/patch/definition" + +/** + * Combines two chunk patches to produce a new chunk patch that describes + * applying their changes sequentially. + * + * @tsplus static Differ.Chunk.Patch.Aspects combine + * @tsplus pipeable Differ.Chunk.Patch combine + */ +export function combine(that: Differ.Chunk.Patch) { + return (self: Differ.Chunk.Patch): Differ.Chunk.Patch => + new AndThenChunkPatch(self, that) +} diff --git a/packages/stdlib/_src/collections/Chunk/patch/operations/diff.ts b/packages/stdlib/_src/collections/Chunk/patch/operations/diff.ts new file mode 100644 index 00000000..77cafba6 --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/operations/diff.ts @@ -0,0 +1,36 @@ +import { + AppendChunkPatch, + SliceChunkPatch, + UpdateChunkPatch +} from "@tsplus/stdlib/collections/Chunk/patch/definition" + +/** + * Constructs a chunk patch from a new and old chunk of values and a differ + * for the values. + * + * @tsplus static Differ.Chunk.Patch.Ops diff + */ +export function diff( + oldValue: Chunk, + newValue: Chunk, + differ: Differ +): Differ.Chunk.Patch { + let i = 0 + let patch = Differ.Chunk.empty() + while (i < oldValue.length && i < newValue.length) { + const oldElement = oldValue.unsafeGet(i) + const newElement = newValue.unsafeGet(i) + const valuePatch = differ.diff(oldElement, newElement) + if (!Equals.equals(valuePatch, differ.empty)) { + patch = patch.combine(new UpdateChunkPatch(i, valuePatch)) + } + i = i + 1 + } + if (i < oldValue.length) { + patch = patch.combine(new SliceChunkPatch(0, i)) + } + if (i < newValue.length) { + patch = patch.combine(new AppendChunkPatch(newValue.drop(i))) + } + return patch +} diff --git a/packages/stdlib/_src/collections/Chunk/patch/operations/emptyPatch.ts b/packages/stdlib/_src/collections/Chunk/patch/operations/emptyPatch.ts new file mode 100644 index 00000000..a98e297c --- /dev/null +++ b/packages/stdlib/_src/collections/Chunk/patch/operations/emptyPatch.ts @@ -0,0 +1,10 @@ +import { EmptyChunkPatch } from "@tsplus/stdlib/collections/Chunk/patch/definition" + +/** + * Constructs an empty chunk patch. + * + * @tsplus static Differ.Chunk.Patch.Ops empty + */ +export function emptyPatch(): Differ.Chunk.Patch { + return new EmptyChunkPatch() +} diff --git a/packages/stdlib/_src/collections/HashMap.ts b/packages/stdlib/_src/collections/HashMap.ts index b1bfe6a2..044cd276 100644 --- a/packages/stdlib/_src/collections/HashMap.ts +++ b/packages/stdlib/_src/collections/HashMap.ts @@ -1,43 +1,14 @@ -export { equals, equals_, getHash, getHash_, has, has_ } from "@tsplus/stdlib/collections/HashMap/_internal/hashMap" +export { + equals, + equals_, + getHash, + getHash_, + has, + has_ +} from "@tsplus/stdlib/collections/HashMap/_internal/hashMap" // codegen:start {preset: barrel, include: ./HashMap/*.ts, prefix: "@tsplus/stdlib/collections"} -export * from "@tsplus/stdlib/collections/HashMap/beginMutation" -export * from "@tsplus/stdlib/collections/HashMap/collect" -export * from "@tsplus/stdlib/collections/HashMap/collectWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/compact" export * from "@tsplus/stdlib/collections/HashMap/definition" -export * from "@tsplus/stdlib/collections/HashMap/empty" -export * from "@tsplus/stdlib/collections/HashMap/endMutation" -export * from "@tsplus/stdlib/collections/HashMap/filter" -export * from "@tsplus/stdlib/collections/HashMap/filterWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/flatMap" -export * from "@tsplus/stdlib/collections/HashMap/flatMapWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/forEach" -export * from "@tsplus/stdlib/collections/HashMap/forEachWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/from" -export * from "@tsplus/stdlib/collections/HashMap/get" -export * from "@tsplus/stdlib/collections/HashMap/getAssociative" -export * from "@tsplus/stdlib/collections/HashMap/hasHash" -export * from "@tsplus/stdlib/collections/HashMap/isEmpty" -export * from "@tsplus/stdlib/collections/HashMap/keys" -export * from "@tsplus/stdlib/collections/HashMap/keySet" -export * from "@tsplus/stdlib/collections/HashMap/make" -export * from "@tsplus/stdlib/collections/HashMap/map" -export * from "@tsplus/stdlib/collections/HashMap/mapWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/modify" -export * from "@tsplus/stdlib/collections/HashMap/modifyHash" -export * from "@tsplus/stdlib/collections/HashMap/mutate" -export * from "@tsplus/stdlib/collections/HashMap/node" -export * from "@tsplus/stdlib/collections/HashMap/reduce" -export * from "@tsplus/stdlib/collections/HashMap/reduceWithIndex" -export * from "@tsplus/stdlib/collections/HashMap/remove" -export * from "@tsplus/stdlib/collections/HashMap/removeMany" -export * from "@tsplus/stdlib/collections/HashMap/set" -export * from "@tsplus/stdlib/collections/HashMap/setTree" -export * from "@tsplus/stdlib/collections/HashMap/size" -export * from "@tsplus/stdlib/collections/HashMap/toCollection" -export * from "@tsplus/stdlib/collections/HashMap/union" -export * from "@tsplus/stdlib/collections/HashMap/unsafeGet" -export * from "@tsplus/stdlib/collections/HashMap/update" -export * from "@tsplus/stdlib/collections/HashMap/values" +export * from "@tsplus/stdlib/collections/HashMap/operations" +export * from "@tsplus/stdlib/collections/HashMap/patch" // codegen:end diff --git a/packages/stdlib/_src/collections/HashMap/operations.ts b/packages/stdlib/_src/collections/HashMap/operations.ts new file mode 100644 index 00000000..9d3ce388 --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/operations.ts @@ -0,0 +1,40 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/HashMap"} +export * from "@tsplus/stdlib/collections/HashMap/operations/beginMutation" +export * from "@tsplus/stdlib/collections/HashMap/operations/collect" +export * from "@tsplus/stdlib/collections/HashMap/operations/collectWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/compact" +export * from "@tsplus/stdlib/collections/HashMap/operations/empty" +export * from "@tsplus/stdlib/collections/HashMap/operations/endMutation" +export * from "@tsplus/stdlib/collections/HashMap/operations/filter" +export * from "@tsplus/stdlib/collections/HashMap/operations/filterWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/flatMap" +export * from "@tsplus/stdlib/collections/HashMap/operations/flatMapWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/forEach" +export * from "@tsplus/stdlib/collections/HashMap/operations/forEachWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/from" +export * from "@tsplus/stdlib/collections/HashMap/operations/get" +export * from "@tsplus/stdlib/collections/HashMap/operations/getAssociative" +export * from "@tsplus/stdlib/collections/HashMap/operations/hasHash" +export * from "@tsplus/stdlib/collections/HashMap/operations/isEmpty" +export * from "@tsplus/stdlib/collections/HashMap/operations/keys" +export * from "@tsplus/stdlib/collections/HashMap/operations/keySet" +export * from "@tsplus/stdlib/collections/HashMap/operations/make" +export * from "@tsplus/stdlib/collections/HashMap/operations/map" +export * from "@tsplus/stdlib/collections/HashMap/operations/mapWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/modify" +export * from "@tsplus/stdlib/collections/HashMap/operations/modifyHash" +export * from "@tsplus/stdlib/collections/HashMap/operations/mutate" +export * from "@tsplus/stdlib/collections/HashMap/operations/node" +export * from "@tsplus/stdlib/collections/HashMap/operations/reduce" +export * from "@tsplus/stdlib/collections/HashMap/operations/reduceWithIndex" +export * from "@tsplus/stdlib/collections/HashMap/operations/remove" +export * from "@tsplus/stdlib/collections/HashMap/operations/removeMany" +export * from "@tsplus/stdlib/collections/HashMap/operations/set" +export * from "@tsplus/stdlib/collections/HashMap/operations/setTree" +export * from "@tsplus/stdlib/collections/HashMap/operations/size" +export * from "@tsplus/stdlib/collections/HashMap/operations/toCollection" +export * from "@tsplus/stdlib/collections/HashMap/operations/union" +export * from "@tsplus/stdlib/collections/HashMap/operations/unsafeGet" +export * from "@tsplus/stdlib/collections/HashMap/operations/update" +export * from "@tsplus/stdlib/collections/HashMap/operations/values" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashMap/beginMutation.ts b/packages/stdlib/_src/collections/HashMap/operations/beginMutation.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/beginMutation.ts rename to packages/stdlib/_src/collections/HashMap/operations/beginMutation.ts diff --git a/packages/stdlib/_src/collections/HashMap/collect.ts b/packages/stdlib/_src/collections/HashMap/operations/collect.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/collect.ts rename to packages/stdlib/_src/collections/HashMap/operations/collect.ts diff --git a/packages/stdlib/_src/collections/HashMap/collectWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/collectWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/compact.ts b/packages/stdlib/_src/collections/HashMap/operations/compact.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/compact.ts rename to packages/stdlib/_src/collections/HashMap/operations/compact.ts diff --git a/packages/stdlib/_src/collections/HashMap/empty.ts b/packages/stdlib/_src/collections/HashMap/operations/empty.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/empty.ts rename to packages/stdlib/_src/collections/HashMap/operations/empty.ts diff --git a/packages/stdlib/_src/collections/HashMap/endMutation.ts b/packages/stdlib/_src/collections/HashMap/operations/endMutation.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/endMutation.ts rename to packages/stdlib/_src/collections/HashMap/operations/endMutation.ts diff --git a/packages/stdlib/_src/collections/HashMap/filter.ts b/packages/stdlib/_src/collections/HashMap/operations/filter.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/filter.ts rename to packages/stdlib/_src/collections/HashMap/operations/filter.ts diff --git a/packages/stdlib/_src/collections/HashMap/filterWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/filterWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/flatMap.ts b/packages/stdlib/_src/collections/HashMap/operations/flatMap.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/flatMap.ts rename to packages/stdlib/_src/collections/HashMap/operations/flatMap.ts diff --git a/packages/stdlib/_src/collections/HashMap/flatMapWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/flatMapWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/flatMapWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/flatMapWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/forEach.ts b/packages/stdlib/_src/collections/HashMap/operations/forEach.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/forEach.ts rename to packages/stdlib/_src/collections/HashMap/operations/forEach.ts diff --git a/packages/stdlib/_src/collections/HashMap/forEachWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/forEachWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/forEachWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/forEachWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/from.ts b/packages/stdlib/_src/collections/HashMap/operations/from.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/from.ts rename to packages/stdlib/_src/collections/HashMap/operations/from.ts diff --git a/packages/stdlib/_src/collections/HashMap/get.ts b/packages/stdlib/_src/collections/HashMap/operations/get.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/get.ts rename to packages/stdlib/_src/collections/HashMap/operations/get.ts diff --git a/packages/stdlib/_src/collections/HashMap/getAssociative.ts b/packages/stdlib/_src/collections/HashMap/operations/getAssociative.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/getAssociative.ts rename to packages/stdlib/_src/collections/HashMap/operations/getAssociative.ts diff --git a/packages/stdlib/_src/collections/HashMap/hasHash.ts b/packages/stdlib/_src/collections/HashMap/operations/hasHash.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/hasHash.ts rename to packages/stdlib/_src/collections/HashMap/operations/hasHash.ts diff --git a/packages/stdlib/_src/collections/HashMap/isEmpty.ts b/packages/stdlib/_src/collections/HashMap/operations/isEmpty.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/isEmpty.ts rename to packages/stdlib/_src/collections/HashMap/operations/isEmpty.ts diff --git a/packages/stdlib/_src/collections/HashMap/keySet.ts b/packages/stdlib/_src/collections/HashMap/operations/keySet.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/keySet.ts rename to packages/stdlib/_src/collections/HashMap/operations/keySet.ts diff --git a/packages/stdlib/_src/collections/HashMap/keys.ts b/packages/stdlib/_src/collections/HashMap/operations/keys.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/keys.ts rename to packages/stdlib/_src/collections/HashMap/operations/keys.ts diff --git a/packages/stdlib/_src/collections/HashMap/make.ts b/packages/stdlib/_src/collections/HashMap/operations/make.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/make.ts rename to packages/stdlib/_src/collections/HashMap/operations/make.ts diff --git a/packages/stdlib/_src/collections/HashMap/map.ts b/packages/stdlib/_src/collections/HashMap/operations/map.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/map.ts rename to packages/stdlib/_src/collections/HashMap/operations/map.ts diff --git a/packages/stdlib/_src/collections/HashMap/mapWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/mapWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/mapWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/mapWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/modify.ts b/packages/stdlib/_src/collections/HashMap/operations/modify.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/modify.ts rename to packages/stdlib/_src/collections/HashMap/operations/modify.ts diff --git a/packages/stdlib/_src/collections/HashMap/modifyHash.ts b/packages/stdlib/_src/collections/HashMap/operations/modifyHash.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/modifyHash.ts rename to packages/stdlib/_src/collections/HashMap/operations/modifyHash.ts diff --git a/packages/stdlib/_src/collections/HashMap/mutate.ts b/packages/stdlib/_src/collections/HashMap/operations/mutate.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/mutate.ts rename to packages/stdlib/_src/collections/HashMap/operations/mutate.ts diff --git a/packages/stdlib/_src/collections/HashMap/node.ts b/packages/stdlib/_src/collections/HashMap/operations/node.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/node.ts rename to packages/stdlib/_src/collections/HashMap/operations/node.ts diff --git a/packages/stdlib/_src/collections/HashMap/reduce.ts b/packages/stdlib/_src/collections/HashMap/operations/reduce.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/reduce.ts rename to packages/stdlib/_src/collections/HashMap/operations/reduce.ts diff --git a/packages/stdlib/_src/collections/HashMap/reduceWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/reduceWithIndex.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/reduceWithIndex.ts rename to packages/stdlib/_src/collections/HashMap/operations/reduceWithIndex.ts diff --git a/packages/stdlib/_src/collections/HashMap/remove.ts b/packages/stdlib/_src/collections/HashMap/operations/remove.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/remove.ts rename to packages/stdlib/_src/collections/HashMap/operations/remove.ts diff --git a/packages/stdlib/_src/collections/HashMap/removeMany.ts b/packages/stdlib/_src/collections/HashMap/operations/removeMany.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/removeMany.ts rename to packages/stdlib/_src/collections/HashMap/operations/removeMany.ts diff --git a/packages/stdlib/_src/collections/HashMap/set.ts b/packages/stdlib/_src/collections/HashMap/operations/set.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/set.ts rename to packages/stdlib/_src/collections/HashMap/operations/set.ts diff --git a/packages/stdlib/_src/collections/HashMap/setTree.ts b/packages/stdlib/_src/collections/HashMap/operations/setTree.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/setTree.ts rename to packages/stdlib/_src/collections/HashMap/operations/setTree.ts diff --git a/packages/stdlib/_src/collections/HashMap/size.ts b/packages/stdlib/_src/collections/HashMap/operations/size.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/size.ts rename to packages/stdlib/_src/collections/HashMap/operations/size.ts diff --git a/packages/stdlib/_src/collections/HashMap/toCollection.ts b/packages/stdlib/_src/collections/HashMap/operations/toCollection.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/toCollection.ts rename to packages/stdlib/_src/collections/HashMap/operations/toCollection.ts diff --git a/packages/stdlib/_src/collections/HashMap/union.ts b/packages/stdlib/_src/collections/HashMap/operations/union.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/union.ts rename to packages/stdlib/_src/collections/HashMap/operations/union.ts diff --git a/packages/stdlib/_src/collections/HashMap/unsafeGet.ts b/packages/stdlib/_src/collections/HashMap/operations/unsafeGet.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/unsafeGet.ts rename to packages/stdlib/_src/collections/HashMap/operations/unsafeGet.ts diff --git a/packages/stdlib/_src/collections/HashMap/update.ts b/packages/stdlib/_src/collections/HashMap/operations/update.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/update.ts rename to packages/stdlib/_src/collections/HashMap/operations/update.ts diff --git a/packages/stdlib/_src/collections/HashMap/values.ts b/packages/stdlib/_src/collections/HashMap/operations/values.ts similarity index 100% rename from packages/stdlib/_src/collections/HashMap/values.ts rename to packages/stdlib/_src/collections/HashMap/operations/values.ts diff --git a/packages/stdlib/_src/collections/HashMap/patch.ts b/packages/stdlib/_src/collections/HashMap/patch.ts new file mode 100644 index 00000000..bb7cc17d --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch.ts @@ -0,0 +1,4 @@ +// codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/HashMap"} +export * from "@tsplus/stdlib/collections/HashMap/patch/definition" +export * from "@tsplus/stdlib/collections/HashMap/patch/operations" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashMap/patch/definition.ts b/packages/stdlib/_src/collections/HashMap/patch/definition.ts new file mode 100644 index 00000000..663b97dc --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/definition.ts @@ -0,0 +1,113 @@ +export const HashMapPatchSym = Symbol.for("@Differ.HashMap.Patch") +export type HashMapPatchSym = typeof HashMapPatchSym + +export const HashMapPatchKeySym = Symbol.for("@Differ.HashMap.Patch.Key") +export type HashMapPatchKeySym = typeof HashMapPatchKeySym + +export const HashMapPatchValueSym = Symbol.for("@Differ.HashMap.Patch.Value") +export type HashMapPatchValueSym = typeof HashMapPatchValueSym + +export const HashMapPatchPatchSym = Symbol.for("@Differ.HashMap.Patch.Patch") +export type HashMapPatchPatchSym = typeof HashMapPatchPatchSym + +/** + * A patch which describes updates to a map of keys and values. + * + * @tsplus type Differ.HashMap.Patch + */ +export interface HashMapPatch { + readonly [HashMapPatchSym]: HashMapPatchSym + readonly [HashMapPatchKeySym]: (_: Key) => Key + readonly [HashMapPatchValueSym]: (_: Value) => Value + readonly [HashMapPatchPatchSym]: (_: Patch) => Patch +} + +/** + * @tsplus type Differ.HashMap.Patch.Ops + */ +export interface HashMapPatchOps { + readonly $: HashMapPatchAspects +} +/** + * @tsplus static Differ.Ops HashMap + */ +export const HashMapPatch: HashMapPatchOps = { + $: {} +} + +/** + * @tsplus type Differ.HashMap.Patch.Aspects + */ +export interface HashMapPatchAspects {} + +/** + * @tsplus unify Differ.HashMap.Patch + */ +export function unifyHashMapPatch>(self: X): HashMapPatch< + [X] extends [{ [HashMapPatchKeySym]: (_: infer Key) => infer Key }] ? Key : never, + [X] extends [{ [HashMapPatchValueSym]: (_: infer Value) => infer Value }] ? Value : never, + [X] extends [{ [HashMapPatchPatchSym]: (_: infer Patch) => infer Patch }] ? Patch : never +> { + return self +} + +export abstract class BaseHashMapPatch + implements HashMapPatch +{ + readonly [HashMapPatchSym]: HashMapPatchSym = HashMapPatchSym + readonly [HashMapPatchKeySym]!: (_: Key) => Key + readonly [HashMapPatchValueSym]!: (_: Value) => Value + readonly [HashMapPatchPatchSym]!: (_: Patch) => Patch +} + +export class AddHashMapPatch extends BaseHashMapPatch { + readonly _tag = "Add" + constructor(readonly key: Key, readonly value: Value) { + super() + } +} + +export class RemoveHashMapPatch extends BaseHashMapPatch { + readonly _tag = "Remove" + constructor(readonly key: Key) { + super() + } +} + +export class UpdateHashMapPatch extends BaseHashMapPatch { + readonly _tag = "Update" + constructor(readonly key: Key, readonly patch: Patch) { + super() + } +} + +export class EmptyHashMapPatch extends BaseHashMapPatch { + readonly _tag = "Empty" +} + +export class AndThenHashMapPatch extends BaseHashMapPatch { + readonly _tag = "AndThen" + constructor( + readonly first: HashMapPatch, + readonly second: HashMapPatch + ) { + super() + } +} + +export type HashMapPatchInstruction = + | AddHashMapPatch + | RemoveHashMapPatch + | UpdateHashMapPatch + | EmptyHashMapPatch + | AndThenHashMapPatch + +/** + * @tsplus macro identity + */ +export function hashMapPatchInstruction( + self: HashMapPatch +): HashMapPatchInstruction { + // @ts-expect-error + return self +} diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations.ts b/packages/stdlib/_src/collections/HashMap/patch/operations.ts new file mode 100644 index 00000000..55d0ebe6 --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/operations.ts @@ -0,0 +1,6 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/HashMap/patch"} +export * from "@tsplus/stdlib/collections/HashMap/patch/operations/apply" +export * from "@tsplus/stdlib/collections/HashMap/patch/operations/combine" +export * from "@tsplus/stdlib/collections/HashMap/patch/operations/diff" +export * from "@tsplus/stdlib/collections/HashMap/patch/operations/emptyPatch" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations/apply.ts b/packages/stdlib/_src/collections/HashMap/patch/operations/apply.ts new file mode 100644 index 00000000..be691c70 --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/operations/apply.ts @@ -0,0 +1,56 @@ +import { hashMapPatchInstruction } from "@tsplus/stdlib/collections/HashMap/patch/definition" + +/** + * Applies a map patch to a map of keys and values to produce a new map of + * keys and values values which represents the original map of keys and + * values updated with the changes described by this patch. + * + * @tsplus static Differ.HashMap.Patch.Aspects apply + * @tsplus pipeable Differ.HashMap.Patch apply + */ +export function apply( + oldValue: HashMap, + differ: Differ +) { + return (self: Differ.HashMap.Patch): HashMap => + applyLoop(differ, oldValue, List(self)) +} + +/** + * @tsplus tailRec + */ +function applyLoop( + differ: Differ, + map: HashMap, + patches: List> +): HashMap { + if (patches.isNil()) { + return map + } + const patch = hashMapPatchInstruction(patches.head) + const nextPatches = patches.tail + switch (patch._tag) { + case "Add": { + return applyLoop(differ, map.set(patch.key, patch.value), nextPatches) + } + case "AndThen": { + return applyLoop(differ, map, nextPatches.prepend(patch.second).prepend(patch.first)) + } + case "Empty": { + return applyLoop(differ, map, nextPatches) + } + case "Remove": { + return applyLoop(differ, map.remove(patch.key), nextPatches) + } + case "Update": { + return applyLoop( + differ, + map.get(patch.key).fold( + map, + (oldValue) => map.set(patch.key, differ.patch(patch.patch, oldValue)) + ), + nextPatches + ) + } + } +} diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations/combine.ts b/packages/stdlib/_src/collections/HashMap/patch/operations/combine.ts new file mode 100644 index 00000000..2929b68e --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/operations/combine.ts @@ -0,0 +1,13 @@ +import { AndThenHashMapPatch } from "@tsplus/stdlib/collections/HashMap/patch/definition" + +/** + * Combines two map patches to produce a new map patch that describes + * applying their changes sequentially. + * + * @tsplus static Differ.HashMap.Patch.Aspects combine + * @tsplus pipeable Differ.HashMap.Patch combine + */ +export function combine(that: Differ.HashMap.Patch) { + return (self: Differ.HashMap.Patch): Differ.HashMap.Patch => + new AndThenHashMapPatch(self, that) +} diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts b/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts new file mode 100644 index 00000000..3d35925e --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts @@ -0,0 +1,40 @@ +import { + AddHashMapPatch, + RemoveHashMapPatch, + UpdateHashMapPatch +} from "@tsplus/stdlib/collections/HashMap/patch/definition" + +/** + * Constructs a map patch from a new and old map of keys and values and a + * differ for the values. + * + * @tsplus static Differ.HashMap.Patch.Ops diff + */ +export function diff( + oldValue: HashMap, + newValue: HashMap, + differ: Differ +): Differ.HashMap.Patch { + const { tuple: [removed, patch] } = newValue.reduceWithIndex( + Tuple(oldValue, Differ.HashMap.empty()), + ({ tuple: [map, patch] }, key, newValue) => { + const maybe = map.get(key) + switch (maybe._tag) { + case "Some": { + const valuePatch = differ.diff(maybe.value, newValue) + if (Equals.equals(valuePatch, differ.empty)) { + return Tuple(map.remove(key), patch) + } + return Tuple(map.remove(key), patch.combine(new UpdateHashMapPatch(key, valuePatch))) + } + case "None": { + return Tuple(map, patch.combine(new AddHashMapPatch(key, newValue))) + } + } + } + ) + return removed.reduceWithIndex( + patch, + (patch, key, _) => patch.combine(new RemoveHashMapPatch(key)) + ) +} diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations/emptyPatch.ts b/packages/stdlib/_src/collections/HashMap/patch/operations/emptyPatch.ts new file mode 100644 index 00000000..f0f7e7ec --- /dev/null +++ b/packages/stdlib/_src/collections/HashMap/patch/operations/emptyPatch.ts @@ -0,0 +1,10 @@ +import { EmptyHashMapPatch } from "@tsplus/stdlib/collections/HashMap/patch/definition" + +/** + * Constructs an empty map patch. + * + * @tsplus static Differ.HashMap.Patch.Ops empty + */ +export function emptyPatch(): Differ.HashMap.Patch { + return new EmptyHashMapPatch() +} diff --git a/packages/stdlib/_src/collections/HashSet.ts b/packages/stdlib/_src/collections/HashSet.ts index d3b548c0..1b53111e 100644 --- a/packages/stdlib/_src/collections/HashSet.ts +++ b/packages/stdlib/_src/collections/HashSet.ts @@ -1,29 +1,5 @@ // codegen:start {preset: barrel, include: ./HashSet/*.ts, prefix: "@tsplus/stdlib/collections"} -export * from "@tsplus/stdlib/collections/HashSet/add" -export * from "@tsplus/stdlib/collections/HashSet/beginMutation" export * from "@tsplus/stdlib/collections/HashSet/definition" -export * from "@tsplus/stdlib/collections/HashSet/difference" -export * from "@tsplus/stdlib/collections/HashSet/empty" -export * from "@tsplus/stdlib/collections/HashSet/endMutation" -export * from "@tsplus/stdlib/collections/HashSet/equals" -export * from "@tsplus/stdlib/collections/HashSet/every" -export * from "@tsplus/stdlib/collections/HashSet/filter" -export * from "@tsplus/stdlib/collections/HashSet/flatMap" -export * from "@tsplus/stdlib/collections/HashSet/forEach" -export * from "@tsplus/stdlib/collections/HashSet/from" -export * from "@tsplus/stdlib/collections/HashSet/has" -export * from "@tsplus/stdlib/collections/HashSet/intersection" -export * from "@tsplus/stdlib/collections/HashSet/isSubset" -export * from "@tsplus/stdlib/collections/HashSet/make" -export * from "@tsplus/stdlib/collections/HashSet/map" -export * from "@tsplus/stdlib/collections/HashSet/mutate" -export * from "@tsplus/stdlib/collections/HashSet/partition" -export * from "@tsplus/stdlib/collections/HashSet/reduce" -export * from "@tsplus/stdlib/collections/HashSet/remove" -export * from "@tsplus/stdlib/collections/HashSet/size" -export * from "@tsplus/stdlib/collections/HashSet/some" -export * from "@tsplus/stdlib/collections/HashSet/toCollection" -export * from "@tsplus/stdlib/collections/HashSet/toggle" -export * from "@tsplus/stdlib/collections/HashSet/union" -export * from "@tsplus/stdlib/collections/HashSet/values" +export * from "@tsplus/stdlib/collections/HashSet/operations" +export * from "@tsplus/stdlib/collections/HashSet/patch" // codegen:end diff --git a/packages/stdlib/_src/collections/HashSet/operations.ts b/packages/stdlib/_src/collections/HashSet/operations.ts new file mode 100644 index 00000000..a5619baf --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/operations.ts @@ -0,0 +1,28 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/HashSet"} +export * from "@tsplus/stdlib/collections/HashSet/operations/add" +export * from "@tsplus/stdlib/collections/HashSet/operations/beginMutation" +export * from "@tsplus/stdlib/collections/HashSet/operations/difference" +export * from "@tsplus/stdlib/collections/HashSet/operations/empty" +export * from "@tsplus/stdlib/collections/HashSet/operations/endMutation" +export * from "@tsplus/stdlib/collections/HashSet/operations/equals" +export * from "@tsplus/stdlib/collections/HashSet/operations/every" +export * from "@tsplus/stdlib/collections/HashSet/operations/filter" +export * from "@tsplus/stdlib/collections/HashSet/operations/flatMap" +export * from "@tsplus/stdlib/collections/HashSet/operations/forEach" +export * from "@tsplus/stdlib/collections/HashSet/operations/from" +export * from "@tsplus/stdlib/collections/HashSet/operations/has" +export * from "@tsplus/stdlib/collections/HashSet/operations/intersection" +export * from "@tsplus/stdlib/collections/HashSet/operations/isSubset" +export * from "@tsplus/stdlib/collections/HashSet/operations/make" +export * from "@tsplus/stdlib/collections/HashSet/operations/map" +export * from "@tsplus/stdlib/collections/HashSet/operations/mutate" +export * from "@tsplus/stdlib/collections/HashSet/operations/partition" +export * from "@tsplus/stdlib/collections/HashSet/operations/reduce" +export * from "@tsplus/stdlib/collections/HashSet/operations/remove" +export * from "@tsplus/stdlib/collections/HashSet/operations/size" +export * from "@tsplus/stdlib/collections/HashSet/operations/some" +export * from "@tsplus/stdlib/collections/HashSet/operations/toCollection" +export * from "@tsplus/stdlib/collections/HashSet/operations/toggle" +export * from "@tsplus/stdlib/collections/HashSet/operations/union" +export * from "@tsplus/stdlib/collections/HashSet/operations/values" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashSet/add.ts b/packages/stdlib/_src/collections/HashSet/operations/add.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/add.ts rename to packages/stdlib/_src/collections/HashSet/operations/add.ts diff --git a/packages/stdlib/_src/collections/HashSet/beginMutation.ts b/packages/stdlib/_src/collections/HashSet/operations/beginMutation.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/beginMutation.ts rename to packages/stdlib/_src/collections/HashSet/operations/beginMutation.ts diff --git a/packages/stdlib/_src/collections/HashSet/difference.ts b/packages/stdlib/_src/collections/HashSet/operations/difference.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/difference.ts rename to packages/stdlib/_src/collections/HashSet/operations/difference.ts diff --git a/packages/stdlib/_src/collections/HashSet/empty.ts b/packages/stdlib/_src/collections/HashSet/operations/empty.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/empty.ts rename to packages/stdlib/_src/collections/HashSet/operations/empty.ts diff --git a/packages/stdlib/_src/collections/HashSet/endMutation.ts b/packages/stdlib/_src/collections/HashSet/operations/endMutation.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/endMutation.ts rename to packages/stdlib/_src/collections/HashSet/operations/endMutation.ts diff --git a/packages/stdlib/_src/collections/HashSet/equals.ts b/packages/stdlib/_src/collections/HashSet/operations/equals.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/equals.ts rename to packages/stdlib/_src/collections/HashSet/operations/equals.ts diff --git a/packages/stdlib/_src/collections/HashSet/every.ts b/packages/stdlib/_src/collections/HashSet/operations/every.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/every.ts rename to packages/stdlib/_src/collections/HashSet/operations/every.ts diff --git a/packages/stdlib/_src/collections/HashSet/filter.ts b/packages/stdlib/_src/collections/HashSet/operations/filter.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/filter.ts rename to packages/stdlib/_src/collections/HashSet/operations/filter.ts diff --git a/packages/stdlib/_src/collections/HashSet/flatMap.ts b/packages/stdlib/_src/collections/HashSet/operations/flatMap.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/flatMap.ts rename to packages/stdlib/_src/collections/HashSet/operations/flatMap.ts diff --git a/packages/stdlib/_src/collections/HashSet/forEach.ts b/packages/stdlib/_src/collections/HashSet/operations/forEach.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/forEach.ts rename to packages/stdlib/_src/collections/HashSet/operations/forEach.ts diff --git a/packages/stdlib/_src/collections/HashSet/from.ts b/packages/stdlib/_src/collections/HashSet/operations/from.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/from.ts rename to packages/stdlib/_src/collections/HashSet/operations/from.ts diff --git a/packages/stdlib/_src/collections/HashSet/has.ts b/packages/stdlib/_src/collections/HashSet/operations/has.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/has.ts rename to packages/stdlib/_src/collections/HashSet/operations/has.ts diff --git a/packages/stdlib/_src/collections/HashSet/intersection.ts b/packages/stdlib/_src/collections/HashSet/operations/intersection.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/intersection.ts rename to packages/stdlib/_src/collections/HashSet/operations/intersection.ts diff --git a/packages/stdlib/_src/collections/HashSet/isSubset.ts b/packages/stdlib/_src/collections/HashSet/operations/isSubset.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/isSubset.ts rename to packages/stdlib/_src/collections/HashSet/operations/isSubset.ts diff --git a/packages/stdlib/_src/collections/HashSet/make.ts b/packages/stdlib/_src/collections/HashSet/operations/make.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/make.ts rename to packages/stdlib/_src/collections/HashSet/operations/make.ts diff --git a/packages/stdlib/_src/collections/HashSet/map.ts b/packages/stdlib/_src/collections/HashSet/operations/map.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/map.ts rename to packages/stdlib/_src/collections/HashSet/operations/map.ts diff --git a/packages/stdlib/_src/collections/HashSet/mutate.ts b/packages/stdlib/_src/collections/HashSet/operations/mutate.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/mutate.ts rename to packages/stdlib/_src/collections/HashSet/operations/mutate.ts diff --git a/packages/stdlib/_src/collections/HashSet/partition.ts b/packages/stdlib/_src/collections/HashSet/operations/partition.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/partition.ts rename to packages/stdlib/_src/collections/HashSet/operations/partition.ts diff --git a/packages/stdlib/_src/collections/HashSet/reduce.ts b/packages/stdlib/_src/collections/HashSet/operations/reduce.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/reduce.ts rename to packages/stdlib/_src/collections/HashSet/operations/reduce.ts diff --git a/packages/stdlib/_src/collections/HashSet/remove.ts b/packages/stdlib/_src/collections/HashSet/operations/remove.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/remove.ts rename to packages/stdlib/_src/collections/HashSet/operations/remove.ts diff --git a/packages/stdlib/_src/collections/HashSet/size.ts b/packages/stdlib/_src/collections/HashSet/operations/size.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/size.ts rename to packages/stdlib/_src/collections/HashSet/operations/size.ts diff --git a/packages/stdlib/_src/collections/HashSet/some.ts b/packages/stdlib/_src/collections/HashSet/operations/some.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/some.ts rename to packages/stdlib/_src/collections/HashSet/operations/some.ts diff --git a/packages/stdlib/_src/collections/HashSet/toCollection.ts b/packages/stdlib/_src/collections/HashSet/operations/toCollection.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/toCollection.ts rename to packages/stdlib/_src/collections/HashSet/operations/toCollection.ts diff --git a/packages/stdlib/_src/collections/HashSet/toggle.ts b/packages/stdlib/_src/collections/HashSet/operations/toggle.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/toggle.ts rename to packages/stdlib/_src/collections/HashSet/operations/toggle.ts diff --git a/packages/stdlib/_src/collections/HashSet/union.ts b/packages/stdlib/_src/collections/HashSet/operations/union.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/union.ts rename to packages/stdlib/_src/collections/HashSet/operations/union.ts diff --git a/packages/stdlib/_src/collections/HashSet/values.ts b/packages/stdlib/_src/collections/HashSet/operations/values.ts similarity index 100% rename from packages/stdlib/_src/collections/HashSet/values.ts rename to packages/stdlib/_src/collections/HashSet/operations/values.ts diff --git a/packages/stdlib/_src/collections/HashSet/patch.ts b/packages/stdlib/_src/collections/HashSet/patch.ts new file mode 100644 index 00000000..38f372a6 --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch.ts @@ -0,0 +1,4 @@ +// codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/HashSet"} +export * from "@tsplus/stdlib/collections/HashSet/patch/definition" +export * from "@tsplus/stdlib/collections/HashSet/patch/operations" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashSet/patch/definition.ts b/packages/stdlib/_src/collections/HashSet/patch/definition.ts new file mode 100644 index 00000000..5a175869 --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/definition.ts @@ -0,0 +1,86 @@ +export const HashSetPatchSym = Symbol.for("@Differ.HashSet.Patch") +export type HashSetPatchSym = typeof HashSetPatchSym + +export const HashSetPatchValueSym = Symbol.for("@Differ.HashSet.Patch.Value") +export type HashSetPatchValueSym = typeof HashSetPatchValueSym + +/** + * A patch which describes updates to a set of values. + * + * @tsplus type Differ.HashSet.Patch + */ +export interface HashSetPatch { + readonly [HashSetPatchSym]: HashSetPatchSym + readonly [HashSetPatchValueSym]: (_: Value) => Value +} + +/** + * @tsplus type Differ.HashSet.Patch.Ops + */ +export interface HashSetPatchOps { + readonly $: HashSetPatchAspects +} +/** + * @tsplus static Differ.Ops HashSet + */ +export const HashSetPatch: HashSetPatchOps = { + $: {} +} + +/** + * @tsplus type Differ.HashSet.Patch.Aspects + */ +export interface HashSetPatchAspects {} + +/** + * @tsplus unify Differ.HashSet.Patch + */ +export function unifyHashSetPatch>(self: X): HashSetPatch< + [X] extends [{ [HashSetPatchValueSym]: (_: infer Value) => infer Value }] ? Value : never +> { + return self +} + +export abstract class BaseHashSetPatch implements HashSetPatch { + readonly [HashSetPatchSym]: HashSetPatchSym = HashSetPatchSym + readonly [HashSetPatchValueSym]!: (_: Value) => Value +} + +export class AddHashSetPatch extends BaseHashSetPatch { + readonly _tag = "Add" + constructor(readonly value: Value) { + super() + } +} + +export class AndThenHashSetPatch extends BaseHashSetPatch { + readonly _tag = "AndThen" + constructor(readonly first: HashSetPatch, readonly second: HashSetPatch) { + super() + } +} + +export class EmptyHashSetPatch extends BaseHashSetPatch { + readonly _tag = "Empty" +} + +export class RemoveHashSetPatch extends BaseHashSetPatch { + readonly _tag = "Remove" + constructor(readonly value: Value) { + super() + } +} + +export type HashSetPatchInstruction = + | AddHashSetPatch + | AndThenHashSetPatch + | EmptyHashSetPatch + | RemoveHashSetPatch + +/** + * @tsplus macro identity + */ +export function hashSetPatchInstruction(self: HashSetPatch): HashSetPatchInstruction { + // @ts-expect-error + return self +} diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations.ts b/packages/stdlib/_src/collections/HashSet/patch/operations.ts new file mode 100644 index 00000000..f01a68db --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/operations.ts @@ -0,0 +1,6 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/collections/HashSet/patch"} +export * from "@tsplus/stdlib/collections/HashSet/patch/operations/apply" +export * from "@tsplus/stdlib/collections/HashSet/patch/operations/combine" +export * from "@tsplus/stdlib/collections/HashSet/patch/operations/diff" +export * from "@tsplus/stdlib/collections/HashSet/patch/operations/emptyPatch" +// codegen:end diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations/apply.ts b/packages/stdlib/_src/collections/HashSet/patch/operations/apply.ts new file mode 100644 index 00000000..d4efb33a --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/operations/apply.ts @@ -0,0 +1,41 @@ +import { hashSetPatchInstruction } from "@tsplus/stdlib/collections/HashSet/patch/definition" + +/** + * Applies a set patch to a set of values to produce a new set of values + * which represents the original set of values updated with the changes + * described by this patch. + * + * @tsplus static Differ.HashSet.Patch.Aspects apply + * @tsplus pipeable Differ.HashSet.Patch apply + */ +export function apply(oldValue: HashSet) { + return (self: Differ.HashSet.Patch): HashSet => applyLoop(oldValue, List(self)) +} + +/** + * @tsplus tailRec + */ +function applyLoop( + set: HashSet, + patches: List> +): HashSet { + if (patches.isNil()) { + return set + } + const patch = hashSetPatchInstruction(patches.head) + const nextPatches = patches.tail + switch (patch._tag) { + case "Add": { + return applyLoop(set.add(patch.value), nextPatches) + } + case "AndThen": { + return applyLoop(set, nextPatches.prepend(patch.second).prepend(patch.first)) + } + case "Empty": { + return applyLoop(set, nextPatches) + } + case "Remove": { + return applyLoop(set.remove(patch.value), nextPatches) + } + } +} diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations/combine.ts b/packages/stdlib/_src/collections/HashSet/patch/operations/combine.ts new file mode 100644 index 00000000..fc63db1f --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/operations/combine.ts @@ -0,0 +1,13 @@ +import { AndThenHashSetPatch } from "@tsplus/stdlib/collections/HashSet/patch/definition" + +/** + * Combines two set patches to produce a new set patch that describes + * applying their changes sequentially. + * + * @tsplus static Differ.HashSet.Patch.Aspects combine + * @tsplus pipeable Differ.HashSet.Patch combine + */ +export function combine(that: Differ.HashSet.Patch) { + return (self: Differ.HashSet.Patch): Differ.HashSet.Patch => + new AndThenHashSetPatch(self, that) +} diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts b/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts new file mode 100644 index 00000000..5283431e --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts @@ -0,0 +1,25 @@ +import { + AddHashSetPatch, + RemoveHashSetPatch +} from "@tsplus/stdlib/collections/HashSet/patch/definition" + +/** + * Constructs a set patch from a new set of values. + * + * @tsplus static Differ.HashSet.Patch.Ops diff + */ +export function diff( + oldValue: HashSet, + newValue: HashSet +): Differ.HashSet.Patch { + const { tuple: [removed, patch] } = newValue.reduce( + Tuple(oldValue, Differ.HashSet.empty()), + ({ tuple: [set, patch] }, value) => { + if (set.has(value)) { + return Tuple(set.remove(value), patch) + } + return Tuple(set, patch.combine(new AddHashSetPatch(value))) + } + ) + return removed.reduce(patch, (patch, value) => patch.combine(new RemoveHashSetPatch(value))) +} diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations/emptyPatch.ts b/packages/stdlib/_src/collections/HashSet/patch/operations/emptyPatch.ts new file mode 100644 index 00000000..77f84a05 --- /dev/null +++ b/packages/stdlib/_src/collections/HashSet/patch/operations/emptyPatch.ts @@ -0,0 +1,10 @@ +import { EmptyHashSetPatch } from "@tsplus/stdlib/collections/HashSet/patch/definition" + +/** + * Constructs an empty set patch. + * + * @tsplus static Differ.HashSet.Patch.Ops empty + */ +export function emptyPatch(): Differ.HashSet.Patch { + return new EmptyHashSetPatch() +} diff --git a/packages/stdlib/_src/data.ts b/packages/stdlib/_src/data.ts index 40305554..7ea1f459 100644 --- a/packages/stdlib/_src/data.ts +++ b/packages/stdlib/_src/data.ts @@ -2,6 +2,7 @@ export * as atomicBoolean from "@tsplus/stdlib/data/AtomicBoolean" export * as atomicNumber from "@tsplus/stdlib/data/AtomicNumber" export * as atomicReference from "@tsplus/stdlib/data/AtomicReference" export * as case from "@tsplus/stdlib/data/Case" +export * as differ from "@tsplus/stdlib/data/Differ" export * as duration from "@tsplus/stdlib/data/Duration" export * as either from "@tsplus/stdlib/data/Either" export * as function from "@tsplus/stdlib/data/Function" diff --git a/packages/stdlib/_src/data/Differ.ts b/packages/stdlib/_src/data/Differ.ts new file mode 100644 index 00000000..1dc18433 --- /dev/null +++ b/packages/stdlib/_src/data/Differ.ts @@ -0,0 +1,5 @@ +// codegen:start {preset: barrel, include: ./Differ/*.ts, prefix: "@tsplus/stdlib/data"} +export * from "@tsplus/stdlib/data/Differ/definition" +export * from "@tsplus/stdlib/data/Differ/operations" +export * from "@tsplus/stdlib/data/Differ/OrPatch" +// codegen:end diff --git a/packages/stdlib/_src/data/Differ/OrPatch.ts b/packages/stdlib/_src/data/Differ/OrPatch.ts new file mode 100644 index 00000000..b38d9c1a --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch.ts @@ -0,0 +1,4 @@ +// codegen:start {preset: barrel, include: ./OrPatch/*.ts, prefix: "@tsplus/stdlib/data/Differ"} +export * from "@tsplus/stdlib/data/Differ/OrPatch/definition" +export * from "@tsplus/stdlib/data/Differ/OrPatch/operations" +// codegen:end diff --git a/packages/stdlib/_src/data/Differ/OrPatch/definition.ts b/packages/stdlib/_src/data/Differ/OrPatch/definition.ts new file mode 100644 index 00000000..b3f8d857 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/definition.ts @@ -0,0 +1,139 @@ +export const OrPatchSym = Symbol.for("@Differ.Or.Patch") +export type OrPatchSym = typeof OrPatchSym + +export const OrPatchValueSym = Symbol.for("@Differ.Or.Patch.Value") +export type OrPatchValueSym = typeof OrPatchValueSym + +export const OrPatchValue2Sym = Symbol.for("@Differ.Or.Patch.Value2") +export type OrPatchValue2Sym = typeof OrPatchValueSym + +export const OrPatchPatchSym = Symbol.for("@Differ.Or.Patch.Patch") +export type OrPatchPatchSym = typeof OrPatchPatchSym + +export const OrPatchPatch2Sym = Symbol.for("@Differ.Or.Patch.Patch2") +export type OrPatchPatch2Sym = typeof OrPatchPatch2Sym + +/** + * A patch which describes updates to either one value or another. + * + * @tsplus type Differ.Or.Patch + */ +export interface OrPatch { + readonly [OrPatchSym]: OrPatchSym + readonly [OrPatchValueSym]: (_: Value) => Value + readonly [OrPatchValue2Sym]: (_: Value2) => Value2 + readonly [OrPatchPatchSym]: (_: Patch) => Patch + readonly [OrPatchPatch2Sym]: (_: Patch2) => Patch2 +} + +/** + * @tsplus type Differ.Or.Patch.Ops + */ +export interface OrPatchOps { + readonly $: OrPatchAspects +} +/** + * @tsplus static Differ.Ops Or + */ +export const OrPatch: OrPatchOps = { + $: {} +} + +/** + * @tsplus type Differ.Or.Patch.Aspects + */ +export interface OrPatchAspects {} + +/** + * @tsplus unify Differ.Or.Patch + */ +export function unifyOrPatch>(self: X): OrPatch< + [X] extends [{ [OrPatchValueSym]: (_: infer Value) => infer Value }] ? Value : never, + [X] extends [{ [OrPatchValue2Sym]: (_: infer Value2) => infer Value2 }] ? Value2 : never, + [X] extends [{ [OrPatchPatchSym]: (_: infer Patch) => infer Patch }] ? Patch : never, + [X] extends [{ [OrPatchPatch2Sym]: (_: infer Patch2) => infer Patch2 }] ? Patch2 : never +> { + return self +} + +export abstract class BaseOrPatch + implements OrPatch +{ + readonly [OrPatchSym]: OrPatchSym = OrPatchSym + readonly [OrPatchValueSym]!: (_: Value) => Value + readonly [OrPatchValue2Sym]!: (_: Value2) => Value2 + readonly [OrPatchPatchSym]!: (_: Patch) => Patch + readonly [OrPatchPatch2Sym]!: (_: Patch2) => Patch2 +} + +export class AndThenOrPatch + extends BaseOrPatch +{ + readonly _tag = "AndThen" + constructor( + readonly first: OrPatch, + readonly second: OrPatch + ) { + super() + } +} + +export class EmptyOrPatch + extends BaseOrPatch +{ + readonly _tag = "Empty" +} + +export class SetLeftOrPatch + extends BaseOrPatch +{ + readonly _tag = "SetLeft" + constructor(readonly value: Value) { + super() + } +} + +export class SetRightOrPatch + extends BaseOrPatch +{ + readonly _tag = "SetRight" + constructor(readonly value: Value2) { + super() + } +} + +export class UpdateLeftOrPatch + extends BaseOrPatch +{ + readonly _tag = "UpdateLeft" + constructor(readonly patch: Patch) { + super() + } +} + +export class UpdateRightOrPatch + extends BaseOrPatch +{ + readonly _tag = "UpdateRight" + constructor(readonly patch: Patch2) { + super() + } +} + +export type OrPatchInstruction = + | AndThenOrPatch + | EmptyOrPatch + | SetLeftOrPatch + | SetRightOrPatch + | UpdateLeftOrPatch + | UpdateRightOrPatch + +/** + * @tsplus macro identity + */ +export function orPatchInstruction( + self: OrPatch +): OrPatchInstruction { + // @ts-expect-error + return self +} diff --git a/packages/stdlib/_src/data/Differ/OrPatch/operations.ts b/packages/stdlib/_src/data/Differ/OrPatch/operations.ts new file mode 100644 index 00000000..49bbd933 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/operations.ts @@ -0,0 +1,6 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/data/Differ/OrPatch"} +export * from "@tsplus/stdlib/data/Differ/OrPatch/operations/apply" +export * from "@tsplus/stdlib/data/Differ/OrPatch/operations/combine" +export * from "@tsplus/stdlib/data/Differ/OrPatch/operations/diff" +export * from "@tsplus/stdlib/data/Differ/OrPatch/operations/emptyPatch" +// codegen:end diff --git a/packages/stdlib/_src/data/Differ/OrPatch/operations/apply.ts b/packages/stdlib/_src/data/Differ/OrPatch/operations/apply.ts new file mode 100644 index 00000000..a0da327f --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/operations/apply.ts @@ -0,0 +1,77 @@ +import { orPatchInstruction } from "@tsplus/stdlib/data/Differ/OrPatch/definition" + +/** + * Applies an or patch to a value to produce a new value which represents + * the original value updated with the changes described by this patch. + * + * @tsplus static Differ.Or.Patch.Aspects apply + * @tsplus pipeable Differ.Or.Patch apply + */ +export function apply( + oldValue: Either, + left: Differ, + right: Differ +) { + return (self: Differ.Or.Patch): Either => + applyLoop(left, right, oldValue, List(self)) +} + +/** + * @tsplus tailRec + */ +function applyLoop( + left: Differ, + right: Differ, + either: Either, + patches: List> +): Either { + if (patches.isNil()) { + return either + } + const patch = orPatchInstruction(patches.head) + const nextPatches = patches.tail + switch (patch._tag) { + case "AndThen": { + return applyLoop(left, right, either, nextPatches.prepend(patch.second).prepend(patch.first)) + } + case "Empty": { + return applyLoop(left, right, either, nextPatches) + } + case "UpdateLeft": { + switch (either._tag) { + case "Left": { + return applyLoop( + left, + right, + Either.left(left.patch(patch.patch, either.left)), + nextPatches + ) + } + case "Right": { + return applyLoop(left, right, either, nextPatches) + } + } + } + case "UpdateRight": { + switch (either._tag) { + case "Left": { + return applyLoop(left, right, either, nextPatches) + } + case "Right": { + return applyLoop( + left, + right, + Either.right(right.patch(patch.patch, either.right)), + nextPatches + ) + } + } + } + case "SetLeft": { + return applyLoop(left, right, Either.left(patch.value), nextPatches) + } + case "SetRight": { + return applyLoop(left, right, Either.right(patch.value), nextPatches) + } + } +} diff --git a/packages/stdlib/_src/data/Differ/OrPatch/operations/combine.ts b/packages/stdlib/_src/data/Differ/OrPatch/operations/combine.ts new file mode 100644 index 00000000..5f4a7e9b --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/operations/combine.ts @@ -0,0 +1,16 @@ +import { AndThenOrPatch } from "@tsplus/stdlib/data/Differ/OrPatch/definition" + +/** + * Combines two or patches to produce a new or patch that describes applying + * their changes sequentially. + * + * @tsplus static Differ.Or.Patch.Aspects combine + * @tsplus pipeable Differ.Or.Patch combine + */ +export function combine( + that: Differ.Or.Patch +) { + return ( + self: Differ.Or.Patch + ): Differ.Or.Patch => new AndThenOrPatch(self, that) +} diff --git a/packages/stdlib/_src/data/Differ/OrPatch/operations/diff.ts b/packages/stdlib/_src/data/Differ/OrPatch/operations/diff.ts new file mode 100644 index 00000000..4d37a018 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/operations/diff.ts @@ -0,0 +1,51 @@ +import { + EmptyOrPatch, + SetLeftOrPatch, + SetRightOrPatch, + UpdateLeftOrPatch, + UpdateRightOrPatch +} from "@tsplus/stdlib/data/Differ/OrPatch/definition" + +/** + * Constructs an `OrPatch` from a new and old value and a differ for the + * values. + * + * @tsplus static Differ.Or.Patch.Ops diff + */ +export function diff( + oldValue: Either, + newValue: Either, + left: Differ, + right: Differ +): Differ.Or.Patch { + switch (oldValue._tag) { + case "Left": { + switch (newValue._tag) { + case "Left": { + const valuePatch = left.diff(oldValue.left, newValue.left) + if (Equals.equals(valuePatch, left.empty)) { + return new EmptyOrPatch() + } + return new UpdateLeftOrPatch(valuePatch) + } + case "Right": { + return new SetRightOrPatch(newValue.right) + } + } + } + case "Right": { + switch (newValue._tag) { + case "Left": { + return new SetLeftOrPatch(newValue.left) + } + case "Right": { + const valuePatch = right.diff(oldValue.right, newValue.right) + if (Equals.equals(valuePatch, right.empty)) { + return new EmptyOrPatch() + } + return new UpdateRightOrPatch(valuePatch) + } + } + } + } +} diff --git a/packages/stdlib/_src/data/Differ/OrPatch/operations/emptyPatch.ts b/packages/stdlib/_src/data/Differ/OrPatch/operations/emptyPatch.ts new file mode 100644 index 00000000..438baecf --- /dev/null +++ b/packages/stdlib/_src/data/Differ/OrPatch/operations/emptyPatch.ts @@ -0,0 +1,15 @@ +import { EmptyOrPatch } from "@tsplus/stdlib/data/Differ/OrPatch/definition" + +/** + * Constructs an empty or patch. + * + * @tsplus static Differ.Or.Patch.Ops empty + */ +export function emptyPatch(): Differ.Or.Patch< + Value, + Value2, + Patch, + Patch2 +> { + return new EmptyOrPatch() +} diff --git a/packages/stdlib/_src/data/Differ/definition.ts b/packages/stdlib/_src/data/Differ/definition.ts new file mode 100644 index 00000000..bfe861e3 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/definition.ts @@ -0,0 +1,84 @@ +import type { ChunkPatch } from "@tsplus/stdlib/collections/Chunk/patch/definition" +import type { HashMapPatch } from "@tsplus/stdlib/collections/HashMap/patch/definition" +import type { HashSetPatch } from "@tsplus/stdlib/collections/HashSet/patch/definition" +import type { OrPatch } from "@tsplus/stdlib/data/Differ/OrPatch/definition" + +export const DifferSym = Symbol.for("@Differ") +export type DifferSym = typeof DifferSym + +/** + * A `Differ` knows how to compare an old value and new value of + * type `Value` to produce a patch of type `Patch` that describes the + * differences between those values. A `Differ` also knows how to apply a patch + * to an old value to produce a new value that represents the old value updated + * with the changes described by the patch. + * + * A `Differ` can be used to construct a `FiberRef` supporting compositional + * updates using the `FiberRef.makePatch` constructor. + * + * The `Differ` companion object contains constructors for `Differ` values for + * common data types such as `Chunk`, `HashMap`, and `HashSet``. In addition, + * `Differ`values can be transformed using the `transform` operator and combined + * using the `orElseEither` and `zip` operators. This allows creating `Differ` + * values for arbitrarily complex data types compositionally. + * + * @tsplus type Differ + */ +export interface Differ { + readonly [DifferSym]: DifferSym + /** + * An empty patch that describes no changes. + */ + readonly empty: Patch + /** + * Constructs a patch describing the updates to a value from an old value and + * a new value. + */ + readonly diff: (oldValue: Value, newValue: Value) => Patch + /** + * Combines two patches to produce a new patch that describes the updates of + * the first patch and then the updates of the second patch. The combine + * operation should be associative. In addition, if the combine operation is + * commutative then joining multiple fibers concurrently will result in + * deterministic `FiberRef` values. + */ + readonly combine: (first: Patch, second: Patch) => Patch + /** + * Applies a patch to an old value to produce a new value that is equal to the + * old value with the updates described by the patch. + */ + readonly patch: (patch: Patch, oldValue: Value) => Value +} + +export declare namespace Differ { + export namespace Or { + export type Patch = OrPatch + } + + export namespace Chunk { + export type Patch = ChunkPatch + } + + export namespace HashMap { + export type Patch = HashMapPatch + } + + export namespace HashSet { + export type Patch = HashSetPatch + } +} + +/** + * @tsplus type Differ.Ops + */ +export interface DifferOps { + readonly $: DifferAspects +} +export const Differ: DifferOps = { + $: {} +} + +/** + * @tsplus type Differ.Aspects + */ +export interface DifferAspects {} diff --git a/packages/stdlib/_src/data/Differ/operations.ts b/packages/stdlib/_src/data/Differ/operations.ts new file mode 100644 index 00000000..d198a03a --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations.ts @@ -0,0 +1,12 @@ +// codegen:start {preset: barrel, include: ./operations/*.ts, prefix: "@tsplus/stdlib/data/Differ"} +export * from "@tsplus/stdlib/data/Differ/operations/chunk" +export * from "@tsplus/stdlib/data/Differ/operations/environment" +export * from "@tsplus/stdlib/data/Differ/operations/hashMap" +export * from "@tsplus/stdlib/data/Differ/operations/hashSet" +export * from "@tsplus/stdlib/data/Differ/operations/make" +export * from "@tsplus/stdlib/data/Differ/operations/orElseEither" +export * from "@tsplus/stdlib/data/Differ/operations/transform" +export * from "@tsplus/stdlib/data/Differ/operations/update" +export * from "@tsplus/stdlib/data/Differ/operations/updateWith" +export * from "@tsplus/stdlib/data/Differ/operations/zip" +// codegen:end diff --git a/packages/stdlib/_src/data/Differ/operations/chunk.ts b/packages/stdlib/_src/data/Differ/operations/chunk.ts new file mode 100644 index 00000000..56a50c00 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/chunk.ts @@ -0,0 +1,16 @@ +/** + * Constructs a differ that knows how to diff a `Chunk` of values given a + * differ that knows how to diff the values. + * + * @tsplus static Differ.Ops chunk + */ +export function chunk( + differ: Differ +): Differ, Differ.Chunk.Patch> { + return Differ.make({ + empty: Differ.Chunk.empty(), + combine: (first, second) => first.combine(second), + diff: (oldValue, newValue) => Differ.Chunk.diff(oldValue, newValue, differ), + patch: (patch, oldValue) => patch.apply(oldValue, differ) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/environment.ts b/packages/stdlib/_src/data/Differ/operations/environment.ts new file mode 100644 index 00000000..703b5ef8 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/environment.ts @@ -0,0 +1,13 @@ +/** + * Constructs a differ that knows how to diff `Env` values. + * + * @tsplus static Differ.Ops environment + */ +export function environment(): Differ, Service.Patch> { + return Differ.make({ + empty: Service.Patch.empty(), + combine: (first, second) => first.combine(second), + diff: (oldValue, newValue) => Service.Patch.diff(oldValue, newValue), + patch: (patch, oldValue) => patch.patch(oldValue) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/hashMap.ts b/packages/stdlib/_src/data/Differ/operations/hashMap.ts new file mode 100644 index 00000000..38ec8e5c --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/hashMap.ts @@ -0,0 +1,16 @@ +/** + * Constructs a differ that knows how to diff a `HashMap` of keys and values given + * a differ that knows how to diff the values. + * + * @tsplus static Differ.Ops hashMap + */ +export function hashMap( + differ: Differ +): Differ, Differ.HashMap.Patch> { + return Differ.make({ + empty: Differ.HashMap.empty(), + combine: (first, second) => first.combine(second), + diff: (oldValue, newValue) => Differ.HashMap.diff(oldValue, newValue, differ), + patch: (patch, oldValue) => patch.apply(oldValue, differ) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/hashSet.ts b/packages/stdlib/_src/data/Differ/operations/hashSet.ts new file mode 100644 index 00000000..fe5b3eec --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/hashSet.ts @@ -0,0 +1,13 @@ +/** + * Constructs a differ that knows how to diff a `HashSet` of values. + * + * @tsplus static Differ.Ops hashSet + */ +export function hashSet(): Differ, Differ.HashSet.Patch> { + return Differ.make({ + empty: Differ.HashSet.empty(), + combine: (first, second) => first.combine(second), + diff: (oldValue, newValue) => Differ.HashSet.diff(oldValue, newValue), + patch: (patch, oldValue) => patch.apply(oldValue) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/make.ts b/packages/stdlib/_src/data/Differ/operations/make.ts new file mode 100644 index 00000000..1e2660c0 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/make.ts @@ -0,0 +1,19 @@ +import { DifferSym } from "@tsplus/stdlib/data/Differ/definition" + +/** + * Constructs a new `Differ`. + * + * @tsplus static Differ.Ops __call + * @tsplus static Differ.Ops make + */ +export function make(params: { + readonly empty: Patch + readonly diff: (oldValue: Value, newValue: Value) => Patch + readonly combine: (first: Patch, second: Patch) => Patch + readonly patch: (patch: Patch, oldValue: Value) => Value +}): Differ { + return { + [DifferSym]: DifferSym, + ...params + } +} diff --git a/packages/stdlib/_src/data/Differ/operations/orElseEither.ts b/packages/stdlib/_src/data/Differ/operations/orElseEither.ts new file mode 100644 index 00000000..10d35968 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/orElseEither.ts @@ -0,0 +1,18 @@ +/** + * Combines this differ and the specified differ to produce a differ that + * knows how to diff the sum of their values. + * + * @tsplus static Differ.Aspects orElseEither + * @tsplus pipeable Differ orElseEither + */ +export function orElseEither(that: Differ) { + return ( + self: Differ + ): Differ, Differ.Or.Patch> => + Differ.make({ + empty: Differ.Or.empty(), + combine: (first, second) => first.combine(second), + diff: (oldValue, newValue) => Differ.Or.diff(oldValue, newValue, self, that), + patch: (patch, oldValue) => patch.apply(oldValue, self, that) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/transform.ts b/packages/stdlib/_src/data/Differ/operations/transform.ts new file mode 100644 index 00000000..0b8fa162 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/transform.ts @@ -0,0 +1,16 @@ +/** + * Transforms the type of values that this differ knows how to differ using + * the specified functions that map the new and old value types to each other. + * + * @tsplus static Differ.Aspects transform + * @tsplus pipeable Differ transform + */ +export function transform(f: (value: Value) => Value2, g: (value: Value2) => Value) { + return (self: Differ): Differ => + Differ.make({ + empty: self.empty, + combine: (first, second) => self.combine(first, second), + diff: (oldValue, newValue) => self.diff(g(oldValue), g(newValue)), + patch: (patch, oldValue) => f(self.patch(patch, g(oldValue))) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/update.ts b/packages/stdlib/_src/data/Differ/operations/update.ts new file mode 100644 index 00000000..4b2444c7 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/update.ts @@ -0,0 +1,11 @@ +/** + * Constructs a differ that just diffs two values by returning a function that + * sets the value to the new value. This differ does not support combining + * multiple updates to the value compositionally and should only be used when + * there is no compositional way to update them. + * + * @tsplus static Differ.Ops update + */ +export function update(): Differ A> { + return Differ.updateWith((_, a) => a) +} diff --git a/packages/stdlib/_src/data/Differ/operations/updateWith.ts b/packages/stdlib/_src/data/Differ/operations/updateWith.ts new file mode 100644 index 00000000..9f763374 --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/updateWith.ts @@ -0,0 +1,29 @@ +import { constant } from "@tsplus/stdlib/data/Function" + +/** + * A variant of `update` that allows specifying the function that will be used + * to combine old values with new values. + * + * @tsplus static Differ.Ops updateWith + */ +export function updateWith(f: (x: A, y: A) => A): Differ A> { + return Differ.make({ + empty: identity, + combine: (first, second) => { + if (first === identity) { + return second + } + if (second === identity) { + return first + } + return (a) => second(first(a)) + }, + diff: (oldValue, newValue) => { + if (Equals.equals(oldValue, newValue)) { + return identity + } + return constant(newValue) + }, + patch: (patch, oldValue) => f(oldValue, patch(oldValue)) + }) +} diff --git a/packages/stdlib/_src/data/Differ/operations/zip.ts b/packages/stdlib/_src/data/Differ/operations/zip.ts new file mode 100644 index 00000000..7c4b4a3c --- /dev/null +++ b/packages/stdlib/_src/data/Differ/operations/zip.ts @@ -0,0 +1,33 @@ +/** + * Combines this differ and the specified differ to produce a new differ that + * knows how to diff the product of their values. + * + * @tsplus static Differ.Aspects zip + * @tsplus pipeable Differ zip + */ +export function zip(that: Differ) { + return ( + self: Differ + ): Differ, Tuple<[Patch, Patch2]>> => + Differ.make({ + empty: Tuple( + self.empty, + that.empty + ), + combine: (first, second) => + Tuple( + self.combine(first.get(0), second.get(0)), + that.combine(first.get(1), second.get(1)) + ), + diff: (oldValue, newValue) => + Tuple( + self.diff(oldValue.get(0), newValue.get(0)), + that.diff(oldValue.get(1), newValue.get(1)) + ), + patch: (patch, oldValue) => + Tuple( + self.patch(patch.get(0), oldValue.get(0)), + that.patch(patch.get(1), oldValue.get(1)) + ) + }) +} diff --git a/packages/stdlib/_src/global.ts b/packages/stdlib/_src/global.ts index ecf95737..e8454ff7 100644 --- a/packages/stdlib/_src/global.ts +++ b/packages/stdlib/_src/global.ts @@ -101,6 +101,10 @@ import { AtomicReference } from "@tsplus/stdlib/data/AtomicReference" * @tsplus global */ import { Case } from "@tsplus/stdlib/data/Case" +/** + * @tsplus global + */ +import { Differ } from "@tsplus/stdlib/data/Differ/definition" /** * @tsplus global */ diff --git a/packages/stdlib/_test/Differ.test.ts b/packages/stdlib/_test/Differ.test.ts new file mode 100644 index 00000000..d3a3829e --- /dev/null +++ b/packages/stdlib/_test/Differ.test.ts @@ -0,0 +1,116 @@ +function diffLaws( + differ: Differ, + gen: () => Value, + equal: (a: Value, b: Value) => boolean +): void { + describe.concurrent("differ laws", () => { + it("combining patches is associative", () => { + const value1 = gen() + const value2 = gen() + const value3 = gen() + const value4 = gen() + const patch1 = differ.diff(value1, value2) + const patch2 = differ.diff(value2, value3) + const patch3 = differ.diff(value3, value4) + const left = differ.combine(differ.combine(patch1, patch2), patch3) + const right = differ.combine(patch1, differ.combine(patch2, patch3)) + assert.isTrue(equal(differ.patch(left, value1), differ.patch(right, value1))) + }) + + it("combining a patch with an empty patch is an identity", () => { + const oldValue = gen() + const newValue = gen() + const patch = differ.diff(oldValue, newValue) + const left = differ.combine(patch, differ.empty) + const right = differ.combine(differ.empty, patch) + assert.isTrue(equal(differ.patch(left, oldValue), newValue)) + assert.isTrue(equal(differ.patch(right, oldValue), newValue)) + }) + + it("diffing a value with itself returns an empty patch", () => { + const value = gen() + assert.deepStrictEqual(differ.diff(value, value), differ.empty) + }) + + it("diffing and then patching is an identity", () => { + const oldValue = gen() + const newValue = gen() + const patch = differ.diff(oldValue, newValue) + assert.isTrue(equal(differ.patch(patch, oldValue), newValue)) + }) + + it("patching with an empty patch is an identity", () => { + const value = gen() + assert.isTrue(equal(differ.patch(differ.empty, value), value)) + }) + }) +} + +const min = 1 +const max = 100 + +function smallInt(): number { + return Math.floor(Math.random() * (max - min + 1) + min) +} + +function randomChunk(): Chunk { + return Chunk.fill(20, smallInt) +} + +// function randomHashMap(): HashMap { +// return HashMap.from(Chunk.fill(20, smallInt).zip(Chunk.fill(20, smallInt))) +// } + +function randomHashSet(): HashSet { + return HashSet.from(Chunk.fill(20, smallInt)) +} + +function randomEither(): Either { + return Math.random() < 0.5 ? Either.left(smallInt()) : Either.right(smallInt()) +} + +function randomTuple(): Tuple<[number, number]> { + return Tuple(smallInt(), smallInt()) +} + +describe.concurrent("Differ", () => { + describe.concurrent("chunk", () => { + diffLaws( + Differ.chunk number>(Differ.update()), + randomChunk, + Equals.equals + ) + }) + + describe.concurrent("either", () => { + diffLaws( + Differ.update().orElseEither(Differ.update()), + randomEither, + Equals.equals + ) + }) + + describe.concurrent("hashMap", () => { + diffLaws( + Differ.hashMap number>(Differ.update()), + () => HashMap(Tuple(1, 2), Tuple(3, 4), Tuple(5, 6)), + Equals.equals + ) + }) + + describe.concurrent("hashSet", () => { + diffLaws( + Differ.hashSet(), + randomHashSet, + Equals.equals + ) + }) + + describe.concurrent("tuple", () => { + diffLaws( + Differ.update().zip(Differ.update()), + randomTuple, + Equals.equals + ) + }) +}) diff --git a/yarn.lock b/yarn.lock index 85c9a1fa..8ce2f3b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -315,12 +315,12 @@ __metadata: languageName: node linkType: hard -"@changesets/apply-release-plan@npm:^6.0.3": - version: 6.0.3 - resolution: "@changesets/apply-release-plan@npm:6.0.3" +"@changesets/apply-release-plan@npm:^6.0.4": + version: 6.0.4 + resolution: "@changesets/apply-release-plan@npm:6.0.4" dependencies: "@babel/runtime": ^7.10.4 - "@changesets/config": ^2.1.0 + "@changesets/config": ^2.1.1 "@changesets/get-version-range-type": ^0.3.2 "@changesets/git": ^1.4.1 "@changesets/types": ^5.1.0 @@ -332,7 +332,7 @@ __metadata: prettier: ^1.19.1 resolve-from: ^5.0.0 semver: ^5.4.1 - checksum: e40cac11719faf00f6573a647202941737408739f30ab534c0a2d69e6b2247940882dac521f254b936f7321e6ffac5dd104b9efaa2f2ccf429002f7f4cf2fc4c + checksum: 2004339f6daf45b282ae0020903d21796076954453b210d3c7935c01247293d0042d994e982e1bc582b61bfa47bd763b7d323635cb19fcd6a9a0e928d8da8358 languageName: node linkType: hard @@ -370,18 +370,18 @@ __metadata: languageName: node linkType: hard -"@changesets/cli@npm:^2.24.1": - version: 2.24.1 - resolution: "@changesets/cli@npm:2.24.1" +"@changesets/cli@npm:^2.24.2": + version: 2.24.2 + resolution: "@changesets/cli@npm:2.24.2" dependencies: "@babel/runtime": ^7.10.4 - "@changesets/apply-release-plan": ^6.0.3 + "@changesets/apply-release-plan": ^6.0.4 "@changesets/assemble-release-plan": ^5.2.0 "@changesets/changelog-git": ^0.1.12 - "@changesets/config": ^2.1.0 + "@changesets/config": ^2.1.1 "@changesets/errors": ^0.1.4 "@changesets/get-dependents-graph": ^1.3.3 - "@changesets/get-release-plan": ^3.0.12 + "@changesets/get-release-plan": ^3.0.13 "@changesets/git": ^1.4.1 "@changesets/logger": ^0.0.5 "@changesets/pre": ^1.0.12 @@ -409,13 +409,13 @@ __metadata: tty-table: ^4.1.5 bin: changeset: bin.js - checksum: 1860969140fbdfd834e4fcb983dccf8e01cf2d5e7fe48eb793318c0411934e6abd1811711a61b1b379fc23b69a5c625354c85d3162045ef4ec726315a7e0ff2b + checksum: ac0d29bd67b1107d6b8600b3b42c8041fd754378ed2424f60c97e4b84a29ef7b779f4f57d8728e4e164e2cd6756b9f60bf8036784f306a368cc736d34740cb3d languageName: node linkType: hard -"@changesets/config@npm:^2.1.0": - version: 2.1.0 - resolution: "@changesets/config@npm:2.1.0" +"@changesets/config@npm:^2.1.1": + version: 2.1.1 + resolution: "@changesets/config@npm:2.1.1" dependencies: "@changesets/errors": ^0.1.4 "@changesets/get-dependents-graph": ^1.3.3 @@ -424,7 +424,7 @@ __metadata: "@manypkg/get-packages": ^1.1.3 fs-extra: ^7.0.1 micromatch: ^4.0.2 - checksum: 0b7ba7ea965739ede9b935efd8d582ed0c939e3df1b147db93c6572e799b3feb1634036e0222926bf223a5e680b9ff433edddf9d670400a3e7a4986f17c27ed1 + checksum: 12b47efd06f9ca19f00a170517dad0e2041c2f285eff308c37e955893d24e981addc941ae545e23f9507628674ef2b9321d7423fc495bc17d00ea09066d68fc7 languageName: node linkType: hard @@ -460,18 +460,18 @@ __metadata: languageName: node linkType: hard -"@changesets/get-release-plan@npm:^3.0.12": - version: 3.0.12 - resolution: "@changesets/get-release-plan@npm:3.0.12" +"@changesets/get-release-plan@npm:^3.0.13": + version: 3.0.13 + resolution: "@changesets/get-release-plan@npm:3.0.13" dependencies: "@babel/runtime": ^7.10.4 "@changesets/assemble-release-plan": ^5.2.0 - "@changesets/config": ^2.1.0 + "@changesets/config": ^2.1.1 "@changesets/pre": ^1.0.12 "@changesets/read": ^0.5.7 "@changesets/types": ^5.1.0 "@manypkg/get-packages": ^1.1.3 - checksum: 383b325c770344b89dfb417996a311390ea718af638f20833124bf2a493cb614ba3603eb01ff7294d48aa211d99d6fda85bf069e426daf5ebc9ded4c857f0055 + checksum: 0e07169f9f83aa3aec072e0b3f96ef60dbb6d878d496fbbf312cfb0fe953953887a2d69008cee991c22b9fea4a2feebc9c1d783c10829be32cf19fde05e85c9d languageName: node linkType: hard @@ -1013,10 +1013,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^18.6.3": - version: 18.6.3 - resolution: "@types/node@npm:18.6.3" - checksum: 38495b8fd27200d2b7ab9ccd8c1e2475d2411fba15330f2cba869a85ef79dd42382a2658c8dd298ace8c21ed3bfafcdea408faecd74928b144377d07d00e7c8c +"@types/node@npm:*, @types/node@npm:^18.6.4": + version: 18.6.4 + resolution: "@types/node@npm:18.6.4" + checksum: fc453dd2b541f5812ba1a8f957f577727cf2d8aee886f1d5c03eb153b2b3373d2e0953c5bd2b7a5b184073bc317f54ec91f1ec4830a58eda4a833e90654021de languageName: node linkType: hard @@ -7413,12 +7413,12 @@ __metadata: "@babel/core": ^7.18.10 "@babel/plugin-transform-modules-commonjs": ^7.18.6 "@changesets/changelog-github": ^0.4.6 - "@changesets/cli": ^2.24.1 + "@changesets/cli": ^2.24.2 "@effect-ts/build-utils": 0.40.3 "@effect-ts/core": ^0.60.2 "@repo-tooling/eslint-plugin-dprint": ^0.0.4 "@tsplus/installer": 0.0.132 - "@types/node": ^18.6.3 + "@types/node": ^18.6.4 "@types/rimraf": ^3.0.2 "@typescript-eslint/eslint-plugin": ^5.32.0 "@typescript-eslint/parser": ^5.32.0