summaryrefslogtreecommitdiff
path: root/u/types/collections
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-07-27 18:50:33 -0700
committerElizabeth Hunt <me@liz.coffee>2025-07-27 19:31:06 -0700
commit7aa11b7a8abacf81dec20fff21216df35d333756 (patch)
tree40f6a76c37412cf1c5a67f99a4ee30e3aae863c9 /u/types/collections
parente4df72cd446270cf867ec308995a05e21b3aa601 (diff)
downloadci-7aa11b7a8abacf81dec20fff21216df35d333756.tar.gz
ci-7aa11b7a8abacf81dec20fff21216df35d333756.zip
Pulls in pengueno from npm
Diffstat (limited to 'u/types/collections')
-rw-r--r--u/types/collections/cons.ts40
-rw-r--r--u/types/collections/index.ts2
-rw-r--r--u/types/collections/list_zipper.ts70
3 files changed, 0 insertions, 112 deletions
diff --git a/u/types/collections/cons.ts b/u/types/collections/cons.ts
deleted file mode 100644
index 05dbe7c..0000000
--- a/u/types/collections/cons.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { IOptional, Mapper, Optional } from '@emprespresso/pengueno';
-
-export interface ICons<T> extends Iterable<T> {
- readonly value: T;
- readonly next: IOptional<ICons<T>>;
-
- readonly replace: Mapper<T, ICons<T>>;
- readonly before: Mapper<IOptional<ICons<T>>, ICons<T>>;
-}
-
-export class Cons<T> implements ICons<T> {
- constructor(
- public readonly value: T,
- public readonly next: IOptional<ICons<T>> = Optional.none(),
- ) {}
-
- public before(head: IOptional<ICons<T>>): ICons<T> {
- return new Cons<T>(this.value, head);
- }
-
- public replace(_value: T): ICons<T> {
- return new Cons<T>(_value, this.next);
- }
-
- *[Symbol.iterator]() {
- for (let cur = Optional.some<ICons<T>>(this); cur.present(); cur = cur.flatMap((cur) => cur.next)) {
- yield cur.get().value;
- }
- }
-
- static addOnto<T>(items: Iterable<T>, tail: IOptional<ICons<T>>): IOptional<ICons<T>> {
- return Array.from(items)
- .reverse()
- .reduce((cons, value) => Optional.from<ICons<T>>(new Cons<T>(value, cons)), tail);
- }
-
- static from<T>(items: Iterable<T>): IOptional<ICons<T>> {
- return Cons.addOnto(items, Optional.none());
- }
-}
diff --git a/u/types/collections/index.ts b/u/types/collections/index.ts
deleted file mode 100644
index 69e5d0b..0000000
--- a/u/types/collections/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './cons.js';
-export * from './list_zipper.js';
diff --git a/u/types/collections/list_zipper.ts b/u/types/collections/list_zipper.ts
deleted file mode 100644
index 3df15b5..0000000
--- a/u/types/collections/list_zipper.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { Cons, ICons } from './cons.js';
-import { IOptional, Mapper, Optional, Supplier } from '@emprespresso/pengueno';
-
-export interface IZipper<T> extends Iterable<T> {
- readonly read: Supplier<IOptional<T>>;
- readonly next: Supplier<IOptional<IZipper<T>>>;
- readonly previous: Supplier<IOptional<IZipper<T>>>;
-
- readonly prependChunk: Mapper<Iterable<T>, IZipper<T>>;
- readonly prepend: Mapper<T, IZipper<T>>;
- readonly remove: Supplier<IZipper<T>>;
- readonly replace: Mapper<T, IZipper<T>>;
-}
-
-export class ListZipper<T> implements IZipper<T> {
- private constructor(
- private readonly reversedPathToHead: IOptional<ICons<T>>,
- private readonly currentHead: IOptional<ICons<T>>,
- ) {}
-
- public read(): IOptional<T> {
- return this.currentHead.map(({ value }) => value);
- }
-
- public next(): IOptional<IZipper<T>> {
- return this.currentHead.map<IZipper<T>>(
- (head) => new ListZipper<T>(Optional.some(head.before(this.reversedPathToHead)), head.next),
- );
- }
-
- public previous(): IOptional<IZipper<T>> {
- return this.reversedPathToHead.map<IZipper<T>>(
- (lastVisited) => new ListZipper<T>(lastVisited.next, Optional.some(lastVisited.before(this.currentHead))),
- );
- }
-
- public prependChunk(values: Iterable<T>): IZipper<T> {
- return new ListZipper<T>(Cons.addOnto(Array.from(values).reverse(), this.reversedPathToHead), this.currentHead);
- }
-
- public prepend(value: T): IZipper<T> {
- return this.prependChunk([value]);
- }
-
- public remove(): IZipper<T> {
- const newHead = this.currentHead.flatMap((right) => right.next);
- return new ListZipper<T>(this.reversedPathToHead, newHead);
- }
-
- public replace(value: T): IZipper<T> {
- const newHead = this.currentHead.map((right) => right.replace(value));
- return new ListZipper<T>(this.reversedPathToHead, newHead);
- }
-
- *[Symbol.iterator]() {
- let head: ListZipper<T> = this;
- for (let prev = head.previous(); prev.present(); prev = prev.flatMap((p) => p.previous())) {
- head = <ListZipper<T>>prev.get();
- }
- if (head.currentHead.present()) yield* head.currentHead.get();
- }
-
- public collection() {
- return Array.from(this);
- }
-
- static from<T>(iterable: Iterable<T>): ListZipper<T> {
- return new ListZipper(Optional.none(), Cons.from(iterable));
- }
-}