functionalscript
Advanced tools
Comparing version 0.3.8 to 0.3.9
{ | ||
"name": "functionalscript", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -1,2 +0,19 @@ | ||
import * as compare from '../function/compare/module.f.ts'; | ||
/** | ||
* @module | ||
* | ||
* This module provides a collection of utility functions for working with `bigint` values. | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* import { sum, abs, log2, bitLength, mask } from './module.f.ts' | ||
* | ||
* const total = sum([1n, 2n, 3n]) // 6n | ||
* const absoluteValue = abs(-42n) // 42n | ||
* const logValue = log2(8n) // 3n | ||
* const bitCount = bitLength(255n) // 8n | ||
* const bitmask = mask(5n) // 31n | ||
* ``` | ||
*/ | ||
import { type Sign } from '../function/compare/module.f.ts'; | ||
import type * as Operator from '../function/operator/module.f.ts'; | ||
@@ -9,3 +26,3 @@ import { type List } from '../list/module.f.ts'; | ||
export declare const abs: Unary; | ||
export declare const sign: (a: bigint) => compare.Sign; | ||
export declare const sign: (a: bigint) => Sign; | ||
export declare const serialize: (a: bigint) => string; | ||
@@ -12,0 +29,0 @@ /** |
@@ -1,3 +0,19 @@ | ||
import * as compare from "../function/compare/module.f.js"; | ||
const { unsafeCmp } = compare; | ||
/** | ||
* @module | ||
* | ||
* This module provides a collection of utility functions for working with `bigint` values. | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* import { sum, abs, log2, bitLength, mask } from './module.f.ts' | ||
* | ||
* const total = sum([1n, 2n, 3n]) // 6n | ||
* const absoluteValue = abs(-42n) // 42n | ||
* const logValue = log2(8n) // 3n | ||
* const bitCount = bitLength(255n) // 8n | ||
* const bitmask = mask(5n) // 31n | ||
* ``` | ||
*/ | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
import { reduce } from "../list/module.f.js"; | ||
@@ -28,9 +44,7 @@ export const addition = a => b => a + b; | ||
export const log2 = (v) => { | ||
// TODO: use step 32 and `Math.clz32()` at the end. | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32 | ||
if (v <= 0n) { | ||
return -1n; | ||
} | ||
let result = 0n; | ||
let i = 1n; | ||
let result = 31n; | ||
let i = 32n; | ||
while (true) { | ||
@@ -47,4 +61,4 @@ const n = v >> i; | ||
// We know that `v` is not 0 so it doesn't make sense to check `n` when `i` is 0. | ||
// Because of this, We check if `i` is greater than 1 before we divide it by 2. | ||
while (i !== 1n) { | ||
// Because of this, We check if `i` is greater than 32 before we divide it by 2. | ||
while (i !== 32n) { | ||
i >>= 1n; | ||
@@ -57,3 +71,3 @@ const n = v >> i; | ||
} | ||
return result; | ||
return result - BigInt(Math.clz32(Number(v))); | ||
}; | ||
@@ -60,0 +74,0 @@ /** |
declare const _default: { | ||
example: () => void; | ||
benchmark: { | ||
str: () => void; | ||
stringHexLog2: () => void; | ||
oldLog2: () => void; | ||
log2: () => void; | ||
}; | ||
mask: () => void; | ||
@@ -3,0 +10,0 @@ sum: () => void; |
import { sum, abs, serialize, log2, bitLength, mask } from "./module.f.js"; | ||
const oldLog2 = (v) => { | ||
if (v <= 0n) { | ||
return -1n; | ||
} | ||
let result = 0n; | ||
let i = 1n; | ||
while (true) { | ||
const n = v >> i; | ||
if (n === 0n) { | ||
// overshot | ||
break; | ||
} | ||
v = n; | ||
result += i; | ||
i <<= 1n; // multiple by two | ||
} | ||
// We know that `v` is not 0 so it doesn't make sense to check `n` when `i` is 0. | ||
// Because of this, We check if `i` is greater than 1 before we divide it by 2. | ||
while (i !== 1n) { | ||
i >>= 1n; | ||
const n = v >> i; | ||
if (n !== 0n) { | ||
result += i; | ||
v = n; | ||
} | ||
} | ||
return result; | ||
}; | ||
const stringLog2 = (v) => BigInt(v.toString(2).length) - 1n; | ||
const stringHexLog2 = (v) => { | ||
const len = (BigInt(v.toString(16).length) - 1n) << 2n; | ||
const x = v >> len; | ||
return len + 31n - BigInt(Math.clz32(Number(x))); | ||
}; | ||
const benchmark = (f) => () => { | ||
let e = 1048575n; | ||
let c = 1n << e; | ||
for (let i = 0n; i < 1_000; ++i) { | ||
const x = f(c); | ||
if (x !== e) { | ||
throw x; | ||
} | ||
c >>= 1n; | ||
--e; | ||
} | ||
}; | ||
export default { | ||
example: () => { | ||
const total = sum([1n, 2n, 3n]); // 6n | ||
if (total !== 6n) { | ||
throw total; | ||
} | ||
const absoluteValue = abs(-42n); // 42n | ||
if (absoluteValue !== 42n) { | ||
throw total; | ||
} | ||
const logValue = log2(8n); // 3n | ||
if (logValue !== 3n) { | ||
throw total; | ||
} | ||
const bitCount = bitLength(255n); // 8n | ||
if (bitCount !== 8n) { | ||
throw total; | ||
} | ||
const bitmask = mask(5n); // 31n | ||
if (bitmask !== 31n) { | ||
throw total; | ||
} | ||
}, | ||
benchmark: { | ||
str: benchmark(stringLog2), | ||
stringHexLog2: benchmark(stringHexLog2), | ||
oldLog2: benchmark(oldLog2), | ||
log2: benchmark(log2), | ||
}, | ||
mask: () => { | ||
@@ -4,0 +78,0 @@ const result = mask(3n); // 7n |
@@ -1,11 +0,12 @@ | ||
import * as _ from '../types/module.f.ts'; | ||
import * as List from '../../list/module.f.ts'; | ||
import * as cmp from '../../function/compare/module.f.ts'; | ||
type FirstLeaf1<T> = readonly [cmp.Index3, _.Leaf1<T>]; | ||
type FirstBranch3<T> = readonly [1, _.Branch3<T>]; | ||
type FirstLeaf2<T> = readonly [cmp.Index5, _.Leaf2<T>]; | ||
type FirstBranch5<T> = readonly [1 | 3, _.Branch5<T>]; | ||
import type { Leaf1, Leaf2, Branch3, Branch5, TNode } from '../types/module.f.ts'; | ||
import type * as List from '../../list/module.f.ts'; | ||
import { type Compare } from '../../function/compare/module.f.ts'; | ||
import type { Index3, Index5 } from "../../array/module.f.ts"; | ||
type FirstLeaf1<T> = readonly [Index3, Leaf1<T>]; | ||
type FirstBranch3<T> = readonly [1, Branch3<T>]; | ||
type FirstLeaf2<T> = readonly [Index5, Leaf2<T>]; | ||
type FirstBranch5<T> = readonly [1 | 3, Branch5<T>]; | ||
type First<T> = FirstLeaf1<T> | FirstBranch3<T> | FirstLeaf2<T> | FirstBranch5<T>; | ||
type PathItem3<T> = readonly [0 | 2, _.Branch3<T>]; | ||
type PathItem5<T> = readonly [0 | 2 | 4, _.Branch5<T>]; | ||
type PathItem3<T> = readonly [0 | 2, Branch3<T>]; | ||
type PathItem5<T> = readonly [0 | 2 | 4, Branch5<T>]; | ||
export type PathItem<T> = PathItem3<T> | PathItem5<T>; | ||
@@ -17,5 +18,5 @@ export type Path<T> = List.List<PathItem<T>>; | ||
}; | ||
export declare const find: <T>(c: cmp.Compare<T>) => (node: _.TNode<T>) => Result<T>; | ||
export declare const find: <T>(c: Compare<T>) => (node: TNode<T>) => Result<T>; | ||
export declare const isFound: <T>([i]: First<T>) => boolean; | ||
export declare const value: <T>([i, r]: First<T>) => T | null; | ||
export {}; |
@@ -1,6 +0,2 @@ | ||
import * as _ from "../types/module.f.js"; | ||
import * as List from "../../list/module.f.js"; | ||
import * as cmp from "../../function/compare/module.f.js"; | ||
const { index3, index5 } = cmp; | ||
import * as Array from "../../array/module.f.js"; | ||
import { index3, index5 } from "../../function/compare/module.f.js"; | ||
const child = (item) => item[1][item[0]]; | ||
@@ -7,0 +3,0 @@ export const find = (c) => { |
@@ -5,4 +5,3 @@ import * as _ from "./module.f.js"; | ||
import { sort } from "../../object/module.f.js"; | ||
import * as string from "../../string/module.f.js"; | ||
const { cmp } = string; | ||
import { cmp } from "../../string/module.f.js"; | ||
import * as s from "../set/module.f.js"; | ||
@@ -9,0 +8,0 @@ const jsonStr = json.stringify(sort); |
import { type List } from '../list/module.f.ts'; | ||
import type * as _ from './types/module.f.ts'; | ||
import type { Tree } from './types/module.f.ts'; | ||
export declare const empty: null; | ||
export declare const values: <T>(tree: _.Tree<T>) => List<T>; | ||
export declare const values: <T>(tree: Tree<T>) => List<T>; |
@@ -1,4 +0,4 @@ | ||
import * as _ from '../types/module.f.ts'; | ||
import * as Cmp from '../../function/compare/module.f.ts'; | ||
import type * as _ from '../types/module.f.ts'; | ||
import type * as Cmp from '../../function/compare/module.f.ts'; | ||
export declare const nodeRemove: <T>(c: Cmp.Compare<T>) => (node: _.TNode<T>) => _.Tree<T>; | ||
export declare const remove: <T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>; |
@@ -1,7 +0,4 @@ | ||
import * as _ from "../types/module.f.js"; | ||
import * as Cmp from "../../function/compare/module.f.js"; | ||
import * as find from "../find/module.f.js"; | ||
import * as list from "../../list/module.f.js"; | ||
const { fold, concat, next } = list; | ||
import * as Array from "../../array/module.f.js"; | ||
import * as n from "../../nullable/module.f.js"; | ||
@@ -8,0 +5,0 @@ const { map } = n; |
import * as _ from "./module.f.js"; | ||
import * as s from "../set/module.f.js"; | ||
import * as str from "../../string/module.f.js"; | ||
const { cmp } = str; | ||
import { cmp } from "../../string/module.f.js"; | ||
import * as json from "../../../json/module.f.js"; | ||
import * as o from "../../object/module.f.js"; | ||
const { sort } = o; | ||
import { sort } from "../../object/module.f.js"; | ||
const set = (node) => (value) => s.set(cmp(value))(() => value)(node); | ||
@@ -9,0 +7,0 @@ const remove = (node) => (value) => _.nodeRemove(cmp(value))(node); |
@@ -1,3 +0,3 @@ | ||
import * as _ from '../types/module.f.ts'; | ||
import * as Cmp from '../../function/compare/module.f.ts'; | ||
import type * as _ from '../types/module.f.ts'; | ||
import type * as Cmp from '../../function/compare/module.f.ts'; | ||
export declare const set: <T>(c: Cmp.Compare<T>) => (f: (value: T | null) => T) => (tree: _.Tree<T>) => _.TNode<T>; |
@@ -1,7 +0,3 @@ | ||
import * as _ from "../types/module.f.js"; | ||
import * as btreeFind from "../find/module.f.js"; | ||
const { find } = btreeFind; | ||
import * as Cmp from "../../function/compare/module.f.js"; | ||
import * as list from "../../list/module.f.js"; | ||
const { fold } = list; | ||
import { find } from "../find/module.f.js"; | ||
import { fold } from "../../list/module.f.js"; | ||
const b57 = b => b.length === 5 ? [b] : [[b[0], b[1], b[2]], b[3], [b[4], b[5], b[6]]]; | ||
@@ -8,0 +4,0 @@ const reduceOp = ([i, x]) => a => { |
@@ -1,13 +0,10 @@ | ||
import * as _ from "./module.f.js"; | ||
const { values } = _; | ||
import { values } from "./module.f.js"; | ||
import * as json from "../../json/module.f.js"; | ||
import * as o from "../object/module.f.js"; | ||
const { sort } = o; | ||
import * as str from "../string/module.f.js"; | ||
const { cmp } = str; | ||
import * as list from "../list/module.f.js"; | ||
import { sort } from "../object/module.f.js"; | ||
import { cmp } from "../string/module.f.js"; | ||
import { next, toArray } from "../list/module.f.js"; | ||
import * as s from "./set/module.f.js"; | ||
import * as f from "./find/module.f.js"; | ||
const jsonStr = json.stringify(sort); | ||
const stringify = sequence => jsonStr(list.toArray(sequence)); | ||
const stringify = sequence => jsonStr(toArray(sequence)); | ||
const set = node => value => s.set(cmp(value))(() => value)(node); | ||
@@ -21,3 +18,3 @@ const valueTest1 = () => { | ||
_map = set(_map)('f'); | ||
let result = stringify(values(_map)); | ||
const result = stringify(values(_map)); | ||
if (result !== '["a","b","c","d","e","f"]') { | ||
@@ -31,3 +28,3 @@ throw result; | ||
_map = set(_map)((i * i).toString()); | ||
let result = stringify(values(_map)); | ||
const result = stringify(values(_map)); | ||
if (result !== '["1","100","16","25","36","4","49","64","81","9"]') { | ||
@@ -64,5 +61,5 @@ throw result; | ||
{ | ||
let _item = list.next(values(_map)); | ||
let _item = next(values(_map)); | ||
while (_item !== null) { | ||
_item = list.next(_item.tail); | ||
_item = next(_item.tail); | ||
} | ||
@@ -69,0 +66,0 @@ } |
@@ -1,4 +0,2 @@ | ||
export type Array1<T> = readonly [T]; | ||
export type Array2<T> = readonly [T, T]; | ||
export type Array3<T> = readonly [T, T, T]; | ||
import type { Array1, Array2 } from '../../array/module.f.ts'; | ||
export type Leaf1<T> = Array1<T>; | ||
@@ -5,0 +3,0 @@ export type Leaf2<T> = Array2<T>; |
@@ -1,3 +0,3 @@ | ||
import type * as RangeMap from '../range_map/module.f.ts'; | ||
import type * as SortedSet from '../sorted_set/module.f.ts'; | ||
import type { RangeMap } from '../range_map/module.f.ts'; | ||
import type { SortedSet } from '../sorted_set/module.f.ts'; | ||
export type ByteSet = bigint; | ||
@@ -15,3 +15,3 @@ type Byte = number; | ||
export declare const unset: (n: Byte) => (s: ByteSet) => ByteSet; | ||
export declare const toRangeMap: (n: ByteSet) => (s: string) => RangeMap.RangeMap<SortedSet.SortedSet<string>>; | ||
export declare const toRangeMap: (n: ByteSet) => (s: string) => RangeMap<SortedSet<string>>; | ||
export {}; |
import { compose } from "../function/module.f.js"; | ||
import * as list from "../list/module.f.js"; | ||
const { reverse, countdown, flat, map } = list; | ||
import { reverse, countdown, flat, map } from "../list/module.f.js"; | ||
export const has = n => s => ((s >> BigInt(n)) & 1n) === 1n; | ||
@@ -5,0 +4,0 @@ // create a set |
import * as _ from "./module.f.js"; | ||
import * as list from "../list/module.f.js"; | ||
const { every, countdown, map, toArray } = list; | ||
import { every, countdown, map, toArray } from "../list/module.f.js"; | ||
import * as json from "../../json/module.f.js"; | ||
import * as o from "../object/module.f.js"; | ||
const { sort } = o; | ||
import { sort } from "../object/module.f.js"; | ||
const stringify = json.stringify(sort); | ||
@@ -8,0 +6,0 @@ export default { |
@@ -1,5 +0,2 @@ | ||
import type * as Array from '../../array/module.f.ts'; | ||
export type Index3 = Array.Index3; | ||
export type Index5 = Array.Index5; | ||
type Array2<T> = Array.Array2<T>; | ||
import type { Index3, Index5, Array2 } from '../../array/module.f.ts'; | ||
export type Sign = -1 | 0 | 1; | ||
@@ -10,2 +7,1 @@ export type Compare<T> = (_: T) => Sign; | ||
export declare const unsafeCmp: <T>(a: T) => (b: T) => Sign; | ||
export {}; |
@@ -1,10 +0,8 @@ | ||
import type * as BtreeTypes from '../btree/types/module.f.ts'; | ||
import type * as Compare from '../function/compare/module.f.ts'; | ||
import type { Tree } from '../btree/types/module.f.ts'; | ||
import { type List } from '../list/module.f.ts'; | ||
import type * as Operator from '../function/operator/module.f.ts'; | ||
export type Sign = Compare.Sign; | ||
import type { Reduce } from '../function/operator/module.f.ts'; | ||
export type Entry<T> = readonly [string, T]; | ||
export type Map<T> = BtreeTypes.Tree<Entry<T>>; | ||
export type Map<T> = Tree<Entry<T>>; | ||
export declare const at: (name: string) => <T>(map: Map<T>) => T | null; | ||
export declare const setReduce: <T>(reduce: Operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>; | ||
export declare const setReduce: <T>(reduce: Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>; | ||
export declare const setReplace: (name: string) => <T>(value: T) => (map: Map<T>) => Map<T>; | ||
@@ -11,0 +9,0 @@ export declare const entries: <T>(map: Map<T>) => List<Entry<T>>; |
import { at, setReplace, setReduce, empty, entries, remove } from "./module.f.js"; | ||
import * as seq from "../list/module.f.js"; | ||
import { toArray } from "../list/module.f.js"; | ||
export default { | ||
@@ -93,3 +93,3 @@ main: [ | ||
} | ||
const e = seq.toArray(entries(m)); | ||
const e = toArray(entries(m)); | ||
if (e.length !== 2) { | ||
@@ -96,0 +96,0 @@ throw 'error'; |
import { every, map, countdown } from "../list/module.f.js"; | ||
import * as _ from "./module.f.js"; | ||
import { empty, has, set, setRange, unset, universe, complement } from "./module.f.js"; | ||
export default { | ||
has: () => { | ||
if (_.has(0)(_.empty)) { | ||
throw _.empty; | ||
if (has(0)(empty)) { | ||
throw empty; | ||
} | ||
if (_.has(1)(_.empty)) { | ||
throw _.empty; | ||
if (has(1)(empty)) { | ||
throw empty; | ||
} | ||
if (_.has(15)(_.empty)) { | ||
throw _.empty; | ||
if (has(15)(empty)) { | ||
throw empty; | ||
} | ||
@@ -17,13 +17,13 @@ }, | ||
() => { | ||
const s = _.set(0)(_.empty); | ||
const s = set(0)(empty); | ||
if (s !== 1) { | ||
throw s; | ||
} | ||
if (!_.has(0)(s)) { | ||
if (!has(0)(s)) { | ||
throw s; | ||
} | ||
if (_.has(1)(s)) { | ||
if (has(1)(s)) { | ||
throw s; | ||
} | ||
if (_.has(15)(s)) { | ||
if (has(15)(s)) { | ||
throw s; | ||
@@ -33,13 +33,13 @@ } | ||
() => { | ||
const s = _.set(15)(_.empty); | ||
const s = set(15)(empty); | ||
if (s !== 0x8000) { | ||
throw s; | ||
} | ||
if (_.has(0)(s)) { | ||
if (has(0)(s)) { | ||
throw s; | ||
} | ||
if (_.has(1)(s)) { | ||
if (has(1)(s)) { | ||
throw s; | ||
} | ||
if (!_.has(15)(s)) { | ||
if (!has(15)(s)) { | ||
throw s; | ||
@@ -51,4 +51,4 @@ } | ||
() => { | ||
const a = _.set(0)(_.empty); | ||
const result = _.unset(0)(a); | ||
const a = set(0)(empty); | ||
const result = unset(0)(a); | ||
if (result !== 0) { | ||
@@ -59,4 +59,4 @@ throw result; | ||
() => { | ||
const a = _.set(15)(_.empty); | ||
const result = _.unset(15)(a); | ||
const a = set(15)(empty); | ||
const result = unset(15)(a); | ||
if (result !== 0) { | ||
@@ -68,3 +68,3 @@ throw result; | ||
setRange: () => { | ||
const result = _.setRange([2, 5])(_.empty); | ||
const result = setRange([2, 5])(empty); | ||
if (result !== 60) { | ||
@@ -75,3 +75,3 @@ throw result; | ||
universe: () => { | ||
const x = every(map((v) => _.has(v)(_.universe))(countdown(16))); | ||
const x = every(map((v) => has(v)(universe))(countdown(16))); | ||
if (!x) { | ||
@@ -83,4 +83,4 @@ throw x; | ||
empty: () => { | ||
const r = _.complement(_.empty); | ||
if (r !== _.universe) { | ||
const r = complement(empty); | ||
if (r !== universe) { | ||
throw r; | ||
@@ -90,4 +90,4 @@ } | ||
universe: () => { | ||
const r = _.complement(_.universe); | ||
if (r !== _.empty) { | ||
const r = complement(universe); | ||
if (r !== empty) { | ||
throw r; | ||
@@ -94,0 +94,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import * as _ from "./module.f.js"; | ||
import { map } from "./module.f.js"; | ||
export default () => { | ||
const optionSq = _.map((v) => v * v); | ||
const optionSq = map((v) => v * v); | ||
const sq3 = optionSq(3); | ||
@@ -5,0 +5,0 @@ if (sq3 !== 9) { |
import { type List } from '../list/module.f.ts'; | ||
import * as compare from '../function/compare/module.f.ts'; | ||
import { type Sign } from '../function/compare/module.f.ts'; | ||
export declare const sum: (input: List<number>) => number; | ||
export declare const min: (input: List<number>) => number | null; | ||
export declare const max: (input: List<number>) => number | null; | ||
export declare const cmp: (a: number) => (b: number) => compare.Sign; | ||
export declare const cmp: (a: number) => (b: number) => Sign; |
import { reduce } from "../list/module.f.js"; | ||
import { addition, min as minOp, max as maxOp } from "../function/operator/module.f.js"; | ||
import * as compare from "../function/compare/module.f.js"; | ||
const { unsafeCmp } = compare; | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
export const sum = reduce(addition)(0); | ||
@@ -6,0 +5,0 @@ export const min = reduce(minOp)(null); |
@@ -1,6 +0,6 @@ | ||
import * as _ from "./module.f.js"; | ||
import { at } from "./module.f.js"; | ||
export default { | ||
ctor: () => { | ||
const a = {}; | ||
const value = _.at('constructor')(a); | ||
const value = at('constructor')(a); | ||
if (value !== null) { | ||
@@ -12,3 +12,3 @@ throw value; | ||
const a = { constructor: 42 }; | ||
const value = _.at('constructor')(a); | ||
const value = at('constructor')(a); | ||
if (value !== 42) { | ||
@@ -15,0 +15,0 @@ throw value; |
import { type SortedList } from '../sorted_list/module.f.ts'; | ||
import type * as O from '../function/operator/module.f.ts'; | ||
import type * as Range from '../range/module.f.ts'; | ||
import type { Reduce, Equal } from '../function/operator/module.f.ts'; | ||
import type { Range } from '../range/module.f.ts'; | ||
export type Entry<T> = [T, number]; | ||
@@ -8,8 +8,8 @@ export type RangeMap<T> = SortedList<Entry<T>>; | ||
export type Operators<T> = { | ||
readonly union: O.Reduce<T>; | ||
readonly equal: O.Equal<T>; | ||
readonly union: Reduce<T>; | ||
readonly equal: Equal<T>; | ||
}; | ||
export type RangeMerge<T> = O.Reduce<RangeMap<T>>; | ||
export type RangeMerge<T> = Reduce<RangeMap<T>>; | ||
export declare const merge: <T>(op: Operators<T>) => RangeMerge<T>; | ||
export declare const get: <T>(def: T) => (value: number) => (rm: RangeMapArray<T>) => T; | ||
export declare const fromRange: <T>(def: T) => (r: Range.Range) => (value: T) => RangeMapArray<T>; | ||
export declare const fromRange: <T>(def: T) => (r: Range) => (value: T) => RangeMapArray<T>; |
import * as _ from "./module.f.js"; | ||
import * as compare from "../function/compare/module.f.js"; | ||
const { unsafeCmp } = compare; | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
import * as json from "../../json/module.f.js"; | ||
import * as object from "../object/module.f.js"; | ||
const { sort } = object; | ||
import { sort } from "../object/module.f.js"; | ||
import * as sortedSet from "../sorted_set/module.f.js"; | ||
@@ -8,0 +6,0 @@ import * as list from "../list/module.f.js"; |
@@ -1,18 +0,18 @@ | ||
import * as _ from "./module.f.js"; | ||
import { contains } from "./module.f.js"; | ||
export default () => { | ||
if (!_.contains([0, 5])(1)) { | ||
if (!contains([0, 5])(1)) { | ||
throw 1; | ||
} | ||
if (!_.contains([0, 5])(0)) { | ||
if (!contains([0, 5])(0)) { | ||
throw 0; | ||
} | ||
if (!_.contains([0, 5])(5)) { | ||
if (!contains([0, 5])(5)) { | ||
throw 5; | ||
} | ||
if (_.contains([0, 5])(-1)) { | ||
if (contains([0, 5])(-1)) { | ||
throw -1; | ||
} | ||
if (_.contains([0, 5])(6)) { | ||
if (contains([0, 5])(6)) { | ||
throw 6; | ||
} | ||
}; |
@@ -1,8 +0,8 @@ | ||
import type * as compare from '../function/compare/module.f.ts'; | ||
import type { Sign } from '../function/compare/module.f.ts'; | ||
import { type List } from '../list/module.f.ts'; | ||
import type * as option from '../nullable/module.f.ts'; | ||
import type { Nullable } from '../nullable/module.f.ts'; | ||
export type SortedList<T> = List<T>; | ||
type SortedArray<T> = readonly T[]; | ||
type Cmp<T> = (a: T) => (b: T) => compare.Sign; | ||
export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [option.Nullable<T>, compare.Sign, S]; | ||
type Cmp<T> = (a: T) => (b: T) => Sign; | ||
export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [Nullable<T>, Sign, S]; | ||
export type TailReduce<T, S> = (state: S) => (tail: List<T>) => List<T>; | ||
@@ -9,0 +9,0 @@ type MergeReduce<T, S> = { |
@@ -1,2 +0,2 @@ | ||
import * as _ from "./module.f.js"; | ||
import { find, merge } from "./module.f.js"; | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
@@ -12,3 +12,3 @@ import * as json from "../../json/module.f.js"; | ||
() => { | ||
const result = stringify(toArray(_.merge(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
const result = stringify(toArray(merge(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
if (result !== '[1,2,3,4,5]') { | ||
@@ -19,3 +19,3 @@ throw result; | ||
() => { | ||
const result = stringify(toArray(_.merge(unsafeCmp)([1, 2, 3])([]))); | ||
const result = stringify(toArray(merge(unsafeCmp)([1, 2, 3])([]))); | ||
if (result !== '[1,2,3]') { | ||
@@ -28,3 +28,3 @@ throw result; | ||
const list = countdown(n); | ||
const result = _.merge(reverseCmp)(list)(list); | ||
const result = merge(reverseCmp)(list)(list); | ||
const len = length(result); | ||
@@ -38,3 +38,3 @@ if (len != n) { | ||
() => { | ||
const result = _.find(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = find(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result !== 0) { | ||
@@ -45,3 +45,3 @@ throw result; | ||
() => { | ||
const result = _.find(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = find(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result !== null) { | ||
@@ -52,3 +52,3 @@ throw result; | ||
() => { | ||
const result = _.find(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = find(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result !== null) { | ||
@@ -59,3 +59,3 @@ throw result; | ||
() => { | ||
const result = _.find(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = find(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result !== 80) { | ||
@@ -62,0 +62,0 @@ throw result; |
@@ -1,4 +0,4 @@ | ||
import type * as Compare from '../function/compare/module.f.ts'; | ||
import type { Sign } from '../function/compare/module.f.ts'; | ||
export type SortedSet<T> = readonly T[]; | ||
type Cmp<T> = (a: T) => (b: T) => Compare.Sign; | ||
type Cmp<T> = (a: T) => (b: T) => Sign; | ||
export declare const union: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>; | ||
@@ -5,0 +5,0 @@ export declare const intersect: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>; |
@@ -1,2 +0,2 @@ | ||
import * as _ from "./module.f.js"; | ||
import { has, intersect, union } from "./module.f.js"; | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
@@ -12,3 +12,3 @@ import * as json from "../../json/module.f.js"; | ||
() => { | ||
const result = stringify(toArray(_.union(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
const result = stringify(toArray(union(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
if (result !== '[1,2,3,4,5]') { | ||
@@ -19,3 +19,3 @@ throw result; | ||
() => { | ||
const result = stringify(toArray(_.union(unsafeCmp)([1, 2, 3])([]))); | ||
const result = stringify(toArray(union(unsafeCmp)([1, 2, 3])([]))); | ||
if (result !== '[1,2,3]') { | ||
@@ -28,3 +28,3 @@ throw result; | ||
const sortedSet = toArray(countdown(n)); | ||
const result = _.union(reverseCmp)(sortedSet)(sortedSet); | ||
const result = union(reverseCmp)(sortedSet)(sortedSet); | ||
const len = length(result); | ||
@@ -38,3 +38,3 @@ if (len != n) { | ||
() => { | ||
const result = stringify(toArray(_.intersect(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
const result = stringify(toArray(intersect(unsafeCmp)([2, 3, 4])([1, 3, 5]))); | ||
if (result !== '[3]') { | ||
@@ -45,3 +45,3 @@ throw result; | ||
() => { | ||
const result = stringify(toArray(_.intersect(unsafeCmp)([1, 2, 3])([]))); | ||
const result = stringify(toArray(intersect(unsafeCmp)([1, 2, 3])([]))); | ||
if (result !== '[]') { | ||
@@ -54,3 +54,3 @@ throw result; | ||
() => { | ||
const result = _.has(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = has(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (!result) { | ||
@@ -61,3 +61,3 @@ throw result; | ||
() => { | ||
const result = _.has(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = has(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result) { | ||
@@ -68,3 +68,3 @@ throw result; | ||
() => { | ||
const result = _.has(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = has(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (result) { | ||
@@ -75,3 +75,3 @@ throw result; | ||
() => { | ||
const result = _.has(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
const result = has(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]); | ||
if (!result) { | ||
@@ -78,0 +78,0 @@ throw result; |
@@ -1,6 +0,6 @@ | ||
import type * as BtreeTypes from '../btree/types/module.f.ts'; | ||
import type { Tree } from '../btree/types/module.f.ts'; | ||
import { type List } from '../list/module.f.ts'; | ||
export declare const values: (s: StringSet) => List<string>; | ||
export declare const empty: null; | ||
export type StringSet = BtreeTypes.Tree<string>; | ||
export type StringSet = Tree<string>; | ||
export declare const contains: (value: string) => (set: StringSet) => boolean; | ||
@@ -7,0 +7,0 @@ export declare const set: (value: string) => (s: StringSet) => StringSet; |
@@ -1,9 +0,9 @@ | ||
import * as _ from "./module.f.js"; | ||
import { contains, remove, set } from "./module.f.js"; | ||
export default { | ||
contains: () => { | ||
const r = _.set('hello')(null); | ||
if (!_.contains('hello')(r)) { | ||
const r = set('hello')(null); | ||
if (!contains('hello')(r)) { | ||
throw r; | ||
} | ||
if (_.contains('hello1')(r)) { | ||
if (contains('hello1')(r)) { | ||
throw r; | ||
@@ -13,50 +13,50 @@ } | ||
remove: () => { | ||
let r = _.set('hello')(null); | ||
r = _.set('world')(r); | ||
r = _.set('HELLO')(r); | ||
r = _.set('WORLD!')(r); | ||
if (!_.contains('hello')(r)) { | ||
let r = set('hello')(null); | ||
r = set('world')(r); | ||
r = set('HELLO')(r); | ||
r = set('WORLD!')(r); | ||
if (!contains('hello')(r)) { | ||
throw r; | ||
} | ||
if (_.contains('hello1')(r)) { | ||
if (contains('hello1')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('HELLO')(r)) { | ||
if (!contains('HELLO')(r)) { | ||
throw r; | ||
} | ||
if (_.contains('WORLD')(r)) { | ||
if (contains('WORLD')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('world')(r)) { | ||
if (!contains('world')(r)) { | ||
throw r; | ||
} | ||
if (_.contains('world!')(r)) { | ||
if (contains('world!')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('WORLD!')(r)) { | ||
if (!contains('WORLD!')(r)) { | ||
throw r; | ||
} | ||
// | ||
r = _.remove('hello')(r); | ||
if (_.contains('hello')(r)) { | ||
r = remove('hello')(r); | ||
if (contains('hello')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('world')(r)) { | ||
if (!contains('world')(r)) { | ||
throw r; | ||
} | ||
r = _.remove('world')(r); | ||
if (_.contains('world')(r)) { | ||
r = remove('world')(r); | ||
if (contains('world')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('HELLO')(r)) { | ||
if (!contains('HELLO')(r)) { | ||
throw r; | ||
} | ||
r = _.remove('HELLO')(r); | ||
if (_.contains('HELLO')(r)) { | ||
r = remove('HELLO')(r); | ||
if (contains('HELLO')(r)) { | ||
throw r; | ||
} | ||
if (!_.contains('WORLD!')(r)) { | ||
if (!contains('WORLD!')(r)) { | ||
throw r; | ||
} | ||
r = _.remove('WORLD!')(r); | ||
r = remove('WORLD!')(r); | ||
if (r !== null) { | ||
@@ -63,0 +63,0 @@ throw r; |
import { type List } from '../list/module.f.ts'; | ||
import * as compare from '../function/compare/module.f.ts'; | ||
import { type Sign } from '../function/compare/module.f.ts'; | ||
export declare const join: (_: string) => (input: List<string>) => string; | ||
export declare const concat: (input: List<string>) => string; | ||
export declare const repeat: (n: string) => (v: number) => string; | ||
export declare const cmp: (a: string) => (b: string) => compare.Sign; | ||
export declare const cmp: (a: string) => (b: string) => Sign; |
import { reduce as listReduce, repeat as listRepeat } from "../list/module.f.js"; | ||
import { compose } from "../function/module.f.js"; | ||
import * as compare from "../function/compare/module.f.js"; | ||
const { unsafeCmp } = compare; | ||
import { unsafeCmp } from "../function/compare/module.f.js"; | ||
import { join as joinOp, concat as concatOp } from "../function/operator/module.f.js"; | ||
@@ -6,0 +5,0 @@ const reduce = o => listReduce(o)(''); |
531430
14636