Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Differ data type #198

Merged
merged 1 commit into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-tips-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tsplus/stdlib": patch
---

add Differ data type
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
101 changes: 2 additions & 99 deletions packages/stdlib/_src/collections/Chunk.ts
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions packages/stdlib/_src/collections/Chunk/operations.ts
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions packages/stdlib/_src/collections/Chunk/patch.ts
Original file line number Diff line number Diff line change
@@ -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
102 changes: 102 additions & 0 deletions packages/stdlib/_src/collections/Chunk/patch/definition.ts
Original file line number Diff line number Diff line change
@@ -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<in out Value, in out Patch> {
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<X extends ChunkPatch<any, any>>(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<Value, Patch> implements ChunkPatch<Value, Patch> {
readonly [ChunkPatchSym]: ChunkPatchSym = ChunkPatchSym
readonly [ChunkPatchValueSym]!: (_: Value) => Value
readonly [ChunkPatchPatchSym]!: (_: Patch) => Patch
}

export class AppendChunkPatch<Value, Patch> extends BaseChunkPatch<Value, Patch> {
readonly _tag = "Append"
constructor(readonly values: Chunk<Value>) {
super()
}
}

export class SliceChunkPatch<Value, Patch> extends BaseChunkPatch<Value, Patch> {
readonly _tag = "Slice"
constructor(readonly from: number, readonly until: number) {
super()
}
}

export class UpdateChunkPatch<Value, Patch> extends BaseChunkPatch<Value, Patch> {
readonly _tag = "Update"
constructor(readonly index: number, readonly patch: Patch) {
super()
}
}

export class AndThenChunkPatch<Value, Patch> extends BaseChunkPatch<Value, Patch> {
readonly _tag = "AndThen"
constructor(readonly first: ChunkPatch<Value, Patch>, readonly second: ChunkPatch<Value, Patch>) {
super()
}
}

export class EmptyChunkPatch<Value, Patch> extends BaseChunkPatch<Value, Patch> {
readonly _tag = "Empty"
}

export type ChunkPatchInstruction =
| AppendChunkPatch<any, any>
| SliceChunkPatch<any, any>
| UpdateChunkPatch<any, any>
| AndThenChunkPatch<any, any>
| EmptyChunkPatch<any, any>

/**
* @tsplus macro identity
*/
export function chunkPatchInstruction<Value, Patch>(
self: ChunkPatch<Value, Patch>
): ChunkPatchInstruction {
// @ts-expect-error
return self
}
6 changes: 6 additions & 0 deletions packages/stdlib/_src/collections/Chunk/patch/operations.ts
Original file line number Diff line number Diff line change
@@ -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
Loading