This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Args, Command } from "@effect/cli"; | |
import { NodeContext, NodeRuntime } from "@effect/platform-node"; | |
import { Path, FileSystem as FS } from "@effect/platform"; | |
import { Effect, Stream } from "effect"; | |
import * as Schema from "@effect/schema/Schema"; | |
// Схема статистики файла | |
const StatsContract = Schema.Struct({ | |
chars: Schema.Number, | |
lines: Schema.Number, | |
words: Schema.Number, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type JsonPrimitive = boolean | number | string | null; | |
export type JsonArray = ReadonlyArray<Json>; | |
export type JsonRecord = { readonly [K in string]: Json }; | |
export type Json = JsonPrimitive | JsonArray | JsonRecord; | |
const from = | |
<From>() => | |
<R, To>(schema: Schema.Schema<To, From, R>) => | |
schema; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable, of } from "rxjs"; | |
import { map, flatMap } from "rxjs/operators"; | |
function bindTo<A, N extends string>(name: N) { | |
return function (from: Observable<A>) { | |
return from.pipe( | |
map((x) => ({ [name]: x } as Record<N, A>)) | |
); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Iterableify<T> = Readonly<{ [K in keyof T]: Iterable<T[K]> }>; | |
type IterableifiedToTuple<X extends Iterableify<unknown>> = Readonly< | |
{ | |
[K in keyof X]: X[K] extends Iterable<infer Y> ? Readonly<Y> : never; | |
} | |
>; | |
type IterableifiedToArrays<X extends Iterableify<unknown>> = Readonly< | |
{ | |
[K in keyof X]: X[K] extends Iterable<infer Y> ? ReadonlyArray<Y> : never; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function* subtractWith<TValue, TSelector = unknown>( | |
selector: (x: TValue) => TSelector, | |
minuend: Iterable<TValue>, | |
subtrahend: Iterable<TValue> | |
): Generator<TValue> { | |
for (const minuendEl of minuend) { | |
const comparableA = selector(minuendEl); | |
let isInB = false; | |
for (const subtrahendEl of subtrahend) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Split iterable into two arrays with splitter predicate (may be TypeGuard). | |
* | |
* Example: | |
type AB = { a: number; b: number }; | |
type A1 = { a: 1; b: number }; | |
type A2 = { a: 2; b: number }; | |
const isA1 = (ab: AB): ab is A1 => ab.a === 1; | |
const data: AB[] = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type _VectorOf<T, N extends number, R extends readonly T[]> = R['length'] extends N | |
? R | |
: _VectorOf<T, N, readonly [T, ...R]>; | |
type VectorType<V extends Vector<any, number>> = V extends Vector<infer T, number> ? T : never; | |
type VectorLength<V extends Vector<any, number>> = V['length']; | |
export type Vector<T, N extends number> = N extends N | |
? number extends N | |
? readonly T[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type TNonEmptyArray<T> = readonly [T, ...T[]] & { readonly length: number }; | |
export const NonEmptyArray = { | |
convert<T>(array: readonly T[]): TNonEmptyArray<T> | undefined { | |
if (array.length > 0) { | |
return NonEmptyArray.create(...(array as [T, ...T[]])); | |
} | |
}, | |
create<T>(...elements: readonly [T, ...T[]]): TNonEmptyArray<T> { | |
return [...elements]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InitReadonly, Tag } from '../internal'; | |
import { TNonEmptyArray } from './NonEmptyArray'; | |
import { TNonEmptyArray2 } from './NonEmptyArray2'; | |
type _Split<SS extends string, S extends string> = S extends `${infer L}${SS}${infer R}` | |
? readonly [L, ..._Split<SS, R>] | |
: readonly [S]; | |
export type Split<SS extends string, S extends string> = SS extends '' | |
? S extends '' |