Remove Fluent, Tags

This commit is contained in:
Jon Staab
2024-12-13 15:18:33 -08:00
parent 6235c3f6bb
commit 760d6d07cd
7 changed files with 14 additions and 258 deletions
-71
View File
@@ -1,71 +0,0 @@
import {last} from './Tools'
export class Fluent<T> {
constructor(readonly xs: T[]) {}
static create() {
return this.from([])
}
static from<T>(xs: Iterable<T>) {
return new Fluent<T>(Array.from(xs))
}
clone<K extends Fluent<T>>(this: K, xs: T[]): K {
return new (this.constructor as { new (xs: T[]): K })(xs)
}
valueOf = () => this.xs
first = () => this.xs[0]
nth = (i: number) => this.xs[i]
last = () => last(this.xs)
count = () => this.xs.length
exists = () => this.xs.length > 0
has = (v: T) => this.xs.includes(v)
every = (f: (t: T) => boolean) => this.xs.every(f)
some = (f: (t: T) => boolean) => this.xs.some(f)
find = (f: (t: T) => boolean) => this.xs.find(f)
uniq = () => this.clone(Array.from(new Set(this.xs)))
slice = (a: number, b?: number) => this.clone(this.xs.slice(a, b))
take = (n: number) => this.slice(0, n)
drop = (n: number) => this.slice(n)
filter = (f: (t: T) => boolean) => this.clone(this.xs.filter(f))
reject = (f: (t: T) => boolean) => this.clone(this.xs.filter(t => !f(t)))
keep = (xs: T[]) => this.filter(x => xs.includes(x))
without = (xs: T[]) => this.reject(x => xs.includes(x))
map = (f: (t: T) => T) => this.clone(this.xs.map(f))
mapTo = <U>(f: (t: T) => U) => Fluent.from(this.xs.map(f))
flatMap = <U>(f: (t: T) => U[]) => Fluent.from(this.xs.flatMap(f))
forEach = (f: (t: T, i: number) => void) => this.xs.forEach(f)
join = (s: string) => this.valueOf().join(s)
set = (i: number, x: T) => this.clone([...this.xs.slice(0, i), x, ...this.xs.slice(i + 1)])
concat = (xs: T[]) => this.clone(this.xs.concat(xs))
append = (x: T) => this.concat([x])
prepend = (x: T) => this.clone([x].concat(this.xs))
}
-7
View File
@@ -1088,10 +1088,3 @@ export const hexToBech32 = (prefix: string, hex: string) =>
*/
export const bech32ToHex = (b32: string) =>
utf8.encode(bech32.fromWords(bech32.decode(b32, false).words))
/** Extracts non-function property names from type */
// https://github.com/microsoft/TypeScript/issues/4628#issuecomment-1147905253
export type OmitStatics<T, S extends string> =
T extends {new(...args: infer A): infer R} ?
{new(...args: A): R}&Omit<T, S> :
Omit<T, S>;
-1
View File
@@ -1,7 +1,6 @@
export * from './Context'
export * from './Deferred'
export * from './Emitter'
export * from './Fluent'
export * from './LRUCache'
export * from './Tools'
export * from './Worker'