functionalscript
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -1,2 +0,2 @@ | ||
import * as Operator from '../../types/function/operator/module.f.ts'; | ||
import type * as Operator from '../../types/function/operator/module.f.ts'; | ||
type Reduce = Operator.Reduce<bigint>; | ||
@@ -3,0 +3,0 @@ type Unary = Operator.Unary<bigint, bigint>; |
@@ -1,3 +0,2 @@ | ||
import * as Operator from "../../types/function/operator/module.f.js"; | ||
import { scalar_mul } from "../../types/bigint/module.f.js"; | ||
import { repeat } from "../../types/monoid/module.f.js"; | ||
/** | ||
@@ -36,3 +35,3 @@ * Creates a prime field with the specified prime modulus and associated operations. | ||
const pow2 = a => mul(a)(a); | ||
const pow = scalar_mul({ 0: 1n, add: mul }); | ||
const pow = repeat({ identity: 1n, operation: mul }); | ||
return { | ||
@@ -39,0 +38,0 @@ p, |
@@ -1,2 +0,2 @@ | ||
import * as Operator from '../../types/function/operator/module.f.ts'; | ||
import type * as Operator from '../../types/function/operator/module.f.ts'; | ||
import { type PrimeField } from '../prime_field/module.f.ts'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,4 +0,3 @@ | ||
import * as Operator from "../../types/function/operator/module.f.js"; | ||
import { prime_field, sqrt } from "../prime_field/module.f.js"; | ||
import { scalar_mul } from "../../types/bigint/module.f.js"; | ||
import { repeat } from "../../types/monoid/module.f.js"; | ||
/** | ||
@@ -74,3 +73,3 @@ * Constructs an elliptic curve with the given initialization parameters. | ||
add: addPoint, | ||
mul: scalar_mul({ 0: null, add: addPoint }) | ||
mul: repeat({ identity: null, operation: addPoint }) | ||
}; | ||
@@ -77,0 +76,0 @@ }; |
@@ -10,5 +10,5 @@ import { type List } from '../types/list/module.f.ts'; | ||
export type Node = Element | string; | ||
export declare const element: (element: Element) => List<string>; | ||
export declare const element: (e: Element) => List<string>; | ||
export declare const html: (_: Element) => List<string>; | ||
export declare const htmlToString: (_: Element) => string; | ||
export {}; |
import { map, flatMap, flat, concat as listConcat } from "../types/list/module.f.js"; | ||
import { concat as stringConcat } from "../types/string/module.f.js"; | ||
import * as O from "../types/object/module.f.js"; | ||
import { compose } from "../types/function/module.f.js"; | ||
@@ -30,7 +29,6 @@ import * as utf16 from "../text/utf16/module.f.js"; | ||
]; | ||
const isVoid = tag => voidTagList.includes(tag); | ||
/** | ||
* https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-in-html | ||
*/ | ||
const escapeCharCode = code => { | ||
const escapeCharCode = (code) => { | ||
switch (code) { | ||
@@ -45,16 +43,22 @@ case 0x22: return '"'; | ||
const escape = compose(stringToList)(map(escapeCharCode)); | ||
const node = n => typeof n === 'string' ? escape(n) : element(n); | ||
const node = (n) => typeof n === 'string' ? escape(n) : element(n); | ||
const nodes = flatMap(node); | ||
const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']]); | ||
const attributes = compose(entries)(flatMap(attribute)); | ||
const open = t => a => flat([[`<`, t], attributes(a), [`>`]]); | ||
const element3 = t => ([a, n]) => { | ||
const o = flat([[`<`, t], attributes(a), [`>`]]); | ||
return isVoid(t) ? o : flat([o, nodes(n), ['</', t, '>']]); | ||
const parseElement = (e) => { | ||
const [tag, item1, ...list] = e; | ||
return item1 === undefined ? | ||
[tag, {}, []] : | ||
typeof item1 === 'object' && !(item1 instanceof Array) ? | ||
[tag, item1, list] : | ||
[tag, {}, [item1, ...list]]; | ||
}; | ||
export const element = e => { | ||
const [t, a, ...n] = e; | ||
return element3(t)(a === undefined ? [{}, []] : typeof a === 'object' && !(a instanceof Array) ? [a, n] : [{}, [a, ...n]]); | ||
export const element = (e) => { | ||
const [tag, a, n] = parseElement(e); | ||
const open = flat([[`<`, tag], attributes(a), [`>`]]); | ||
return voidTagList.includes(tag) ? | ||
open : | ||
flat([open, nodes(n), ['</', tag, '>']]); | ||
}; | ||
export const html = compose(element)(listConcat(['<!DOCTYPE html>'])); | ||
export const htmlToString = compose(html)(stringConcat); |
@@ -1,5 +0,5 @@ | ||
import * as _ from "./module.f.js"; | ||
import { htmlToString } from "./module.f.js"; | ||
export default { | ||
empty: () => { | ||
const r = _.htmlToString(['html']); | ||
const r = htmlToString(['html']); | ||
if (r !== '<!DOCTYPE html><html></html>') { | ||
@@ -10,3 +10,3 @@ throw `empty: ${r}`; | ||
empty2: () => { | ||
const r = _.htmlToString(['html']); | ||
const r = htmlToString(['html']); | ||
if (r !== '<!DOCTYPE html><html></html>') { | ||
@@ -17,3 +17,3 @@ throw r; | ||
void: () => { | ||
const r = _.htmlToString(['area']); | ||
const r = htmlToString(['area']); | ||
if (r !== '<!DOCTYPE html><area>') { | ||
@@ -25,3 +25,3 @@ throw r; | ||
const x = ['div', {}, '<div>&</div>', ['a', { href: 'hello"' }]]; | ||
const s = _.htmlToString(x); | ||
const s = htmlToString(x); | ||
if (s !== '<!DOCTYPE html><div><div>&amp;</div><a href="hello""></a></div>') { | ||
@@ -33,3 +33,3 @@ throw s; | ||
const x = ['div', '<div>&</div>', ['a', { href: 'hello"' }]]; | ||
const s = _.htmlToString(x); | ||
const s = htmlToString(x); | ||
if (s !== '<!DOCTYPE html><div><div>&amp;</div><a href="hello""></a></div>') { | ||
@@ -41,3 +41,3 @@ throw s; | ||
const x = ['div', ['br', { id: '5' }], '<div>&</div>', ['a', { href: 'hello"' }]]; | ||
const s = _.htmlToString(x); | ||
const s = htmlToString(x); | ||
if (s !== '<!DOCTYPE html><div><br id="5"><div>&amp;</div><a href="hello""></a></div>') { | ||
@@ -44,0 +44,0 @@ throw s; |
import * as list from '../../types/list/module.f.ts'; | ||
import * as bigfloatT from '../../types/bigfloat/module.f.ts'; | ||
import type * as bigfloatT from '../../types/bigfloat/module.f.ts'; | ||
export type StringToken = { | ||
@@ -4,0 +4,0 @@ readonly kind: 'string'; |
@@ -10,3 +10,2 @@ import * as operator from "../../types/function/operator/module.f.js"; | ||
const { empty, stateScan, flat, toArray, reduce: listReduce, scan } = list; | ||
import * as bigfloatT from "../../types/bigfloat/module.f.js"; | ||
const { fromCharCode } = String; | ||
@@ -13,0 +12,0 @@ import * as ascii from "../../text/ascii/module.f.js"; |
@@ -26,3 +26,31 @@ declare const _default: { | ||
}; | ||
unary_plus: () => { | ||
null: () => void; | ||
undefined: () => void; | ||
boolean: { | ||
false: () => void; | ||
true: () => void; | ||
}; | ||
number: { | ||
zero: () => void; | ||
positive: () => void; | ||
negative: () => void; | ||
}; | ||
string: { | ||
empty: () => void; | ||
zero: () => void; | ||
positive: () => void; | ||
nan: () => void; | ||
}; | ||
array: { | ||
empty: () => void; | ||
single_number: () => void; | ||
single_string: () => void; | ||
multiple: () => void; | ||
}; | ||
object: { | ||
empty: () => void; | ||
}; | ||
}; | ||
}; | ||
export default _default; |
@@ -28,2 +28,3 @@ const e = a => b => { | ||
n(false)(undefined); | ||
n(false)(null); | ||
} | ||
@@ -84,3 +85,47 @@ }, | ||
} | ||
}, | ||
unary_plus: () => { | ||
const op = (n) => +n; | ||
const nan = (n) => { | ||
let result = op(n); | ||
if (!Number.isNaN(result)) { | ||
throw result; | ||
} | ||
}; | ||
return { | ||
null: () => e(op(null))(0), | ||
undefined: () => nan(undefined), | ||
boolean: { | ||
false: () => e(op(false))(0), | ||
true: () => e(op(true))(1) | ||
}, | ||
number: { | ||
zero: () => e(op(0))(0), | ||
positive: () => e(op(2.3))(2.3), | ||
negative: () => e(op(-2.3))(-2.3) | ||
}, | ||
string: { | ||
empty: () => e(op(""))(0), | ||
zero: () => e(op("0"))(0), | ||
positive: () => e(op("2.3"))(2.3), | ||
nan: () => nan("a") | ||
}, | ||
// TODO: bigint - handle TypeError exception for bigint. The test below (that follows | ||
// current Rust implementation) is incorrect. | ||
// bigint: { | ||
// nan: () => u_p_nan(0n) | ||
// } | ||
array: { | ||
empty: () => e(op([]))(0), | ||
single_number: () => e(op([2.3]))(2.3), | ||
single_string: () => e(op(["-2.3"]))(-2.3), | ||
multiple: () => nan([null, null]) | ||
}, | ||
object: { | ||
empty: () => nan({}) | ||
// TODO: test objects with valueOf, toString functions - when Rust logic is implemented | ||
} | ||
// TODO: test Function - when Rust logic is implemented | ||
}; | ||
} | ||
}; |
{ | ||
"name": "functionalscript", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
export type Array1<T> = readonly [T]; | ||
type Index1 = 0; | ||
export type Index1 = 0; | ||
export type Array2<T> = readonly [T, T]; | ||
type Index2 = 0 | 1; | ||
export type Tuple2<T0, T1> = readonly [T0, T1]; | ||
export type Index2 = 0 | 1; | ||
export type Array3<T> = readonly [T, T, T]; | ||
export type Tuple3<T0, T1, T2> = readonly [T0, T1, T2]; | ||
export type Index3 = 0 | 1 | 2; | ||
export type Array4<T> = readonly [T, T, T, T]; | ||
type Index4 = 0 | 1 | 2 | 3; | ||
export type Index4 = 0 | 1 | 2 | 3; | ||
export type Array5<T> = readonly [T, T, T, T, T]; | ||
export type Array8<T> = readonly [T, T, T, T, T, T, T, T]; | ||
export type Array16<T> = readonly [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; | ||
export type Index16 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; | ||
export type Array1_5<T> = Array1<T> | Array2<T> | Array3<T> | Array4<T> | Array5<T>; | ||
export type Index5 = 0 | 1 | 2 | 3 | 4; | ||
export type KeyOf<T> = T extends Array1<infer _> ? Index1 : T extends Array2<infer _> ? Index2 : T extends Array3<infer _> ? Index3 : T extends Array4<infer _> ? Index4 : T extends Array5<infer _> ? Index5 : T extends readonly (infer _)[] ? number : never; | ||
export declare const at: (index: number) => <T>(a: readonly T[]) => T | null; | ||
export declare const at: (i: number) => <T>(a: readonly T[]) => T | null; | ||
export declare const first: <T>(_: readonly T[]) => T | null; | ||
export declare const last: <T>(_: readonly T[]) => T | null; | ||
export declare const tail: <T>(_: readonly T[]) => readonly T[] | null; | ||
export declare const last: <T>(a: readonly T[]) => T | null; | ||
export declare const tail: <T>(a: readonly T[]) => readonly T[] | null; | ||
export declare const splitFirst: <T>(a: readonly T[]) => readonly [T, readonly T[]] | null; | ||
export declare const head: <T>(_: readonly T[]) => readonly T[] | null; | ||
export declare const splitLast: <T>(_: readonly T[]) => readonly [readonly T[], T] | null; | ||
export {}; | ||
export declare const head: <T>(a: readonly T[]) => readonly T[] | null; | ||
export declare const splitLast: <T>(a: readonly T[]) => readonly [readonly T[], T] | null; |
@@ -1,18 +0,17 @@ | ||
import * as option from "../nullable/module.f.js"; | ||
const { map } = option; | ||
const uncheckTail = a => a.slice(1); | ||
const uncheckHead = a => a.slice(0, -1); | ||
export const at = i => a => { | ||
import { map } from "../nullable/module.f.js"; | ||
const uncheckTail = (a) => a.slice(1); | ||
const uncheckHead = (a) => a.slice(0, -1); | ||
export const at = (i) => (a) => { | ||
const r = a[i]; | ||
return r === void 0 ? null : r; | ||
return r === undefined ? null : r; | ||
}; | ||
export const first = at(0); | ||
export const last = a => at(a.length - 1)(a); | ||
export const tail = a => a.length === 0 ? null : uncheckTail(a); | ||
export const last = (a) => at(a.length - 1)(a); | ||
export const tail = (a) => a.length === 0 ? null : uncheckTail(a); | ||
export const splitFirst = (a) => { | ||
const split = first => [first, uncheckTail(a)]; | ||
const split = (first) => [first, uncheckTail(a)]; | ||
return map(split)(first(a)); | ||
}; | ||
export const head = a => a.length === 0 ? null : uncheckHead(a); | ||
export const splitLast = a => { | ||
export const head = (a) => a.length === 0 ? null : uncheckHead(a); | ||
export const splitLast = (a) => { | ||
const lastA = last(a); | ||
@@ -19,0 +18,0 @@ if (lastA === null) { |
@@ -9,3 +9,4 @@ declare const _default: { | ||
splitFirst: (() => void)[]; | ||
splitLast: (() => void)[]; | ||
}; | ||
export default _default; |
@@ -1,5 +0,4 @@ | ||
import * as _ from "./module.f.js"; | ||
import { at, first, last, head, tail, splitFirst, splitLast } from "./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); | ||
@@ -15,3 +14,3 @@ export default { | ||
() => { | ||
const result = _.at(2)([1, 20, 300]); | ||
const result = at(2)([1, 20, 300]); | ||
if (result !== 300) { | ||
@@ -22,3 +21,3 @@ throw result; | ||
() => { | ||
const result = _.at(3)([1, 20, 300]); | ||
const result = at(3)([1, 20, 300]); | ||
if (result !== null) { | ||
@@ -31,3 +30,3 @@ throw result; | ||
() => { | ||
const result = _.first([1, 20, 300]); | ||
const result = first([1, 20, 300]); | ||
if (result !== 1) { | ||
@@ -38,3 +37,3 @@ throw result; | ||
() => { | ||
const result = _.first([]); | ||
const result = first([]); | ||
if (result !== null) { | ||
@@ -47,3 +46,3 @@ throw result; | ||
() => { | ||
const result = _.last([1, 20, 300]); | ||
const result = last([1, 20, 300]); | ||
if (result !== 300) { | ||
@@ -54,3 +53,3 @@ throw result; | ||
() => { | ||
const result = _.last([]); | ||
const result = last([]); | ||
if (result !== null) { | ||
@@ -63,3 +62,3 @@ throw result; | ||
() => { | ||
const result = _.head([1, 20, 300]); | ||
const result = head([1, 20, 300]); | ||
if (result === null) { | ||
@@ -74,3 +73,3 @@ throw result; | ||
() => { | ||
const result = _.head([]); | ||
const result = head([]); | ||
if (result !== null) { | ||
@@ -83,3 +82,3 @@ throw result; | ||
() => { | ||
const result = _.tail([1, 20, 300]); | ||
const result = tail([1, 20, 300]); | ||
const str = stringify(result); | ||
@@ -91,3 +90,3 @@ if (str !== '[20,300]') { | ||
() => { | ||
const result = _.tail([]); | ||
const result = tail([]); | ||
if (result !== null) { | ||
@@ -100,3 +99,3 @@ throw result; | ||
() => { | ||
const result = _.splitFirst([1, 20, 300]); | ||
const result = splitFirst([1, 20, 300]); | ||
const str = stringify(result); | ||
@@ -108,3 +107,3 @@ if (str !== '[1,[20,300]]') { | ||
() => { | ||
const result = _.splitFirst([]); | ||
const result = splitFirst([]); | ||
if (result !== null) { | ||
@@ -114,4 +113,6 @@ throw result; | ||
}, | ||
], | ||
splitLast: [ | ||
() => { | ||
const result = _.splitLast([1, 20, 300]); | ||
const result = splitLast([1, 20, 300]); | ||
const str = stringify(result); | ||
@@ -123,3 +124,3 @@ if (str !== '[[1,20],300]') { | ||
() => { | ||
const result = _.splitLast([]); | ||
const result = splitLast([]); | ||
if (result !== null) { | ||
@@ -126,0 +127,0 @@ throw result; |
export type BigFloat = readonly [bigint, number]; | ||
export declare const multiply: (b: BigFloat) => (mul: bigint) => BigFloat; | ||
export declare const multiply: ([m, e]: BigFloat) => (mul: bigint) => BigFloat; | ||
export declare const decToBin: (dec: BigFloat) => BigFloat; |
@@ -1,6 +0,5 @@ | ||
import * as bi from "../bigint/module.f.js"; | ||
const { abs, sign } = bi; | ||
import { abs, sign } from "../bigint/module.f.js"; | ||
const twoPow53 = 9007199254740992n; | ||
const twoPow54 = 18014398509481984n; | ||
const increaseMantissa = ([m, e]) => min => { | ||
const increaseMantissa = ([m, e]) => (min) => { | ||
if (m === 0n) { | ||
@@ -19,3 +18,3 @@ return [m, e]; | ||
}; | ||
const decreaseMantissa = ([m, e]) => max => { | ||
const decreaseMantissa = ([m, e]) => (max) => { | ||
if (m === 0n) { | ||
@@ -34,6 +33,6 @@ return [m, e]; | ||
}; | ||
const pow = base => exp => base ** BigInt(exp); | ||
const pow = (base) => (exp) => base ** BigInt(exp); | ||
const pow5 = pow(5n); | ||
export const multiply = ([m, e]) => mul => [m * mul, e]; | ||
const divide = ([m, e]) => div => [[m / div, e], m % div]; | ||
export const multiply = ([m, e]) => (mul) => [m * mul, e]; | ||
const divide = ([m, e]) => (div) => [[m / div, e], m % div]; | ||
const round53 = ([[m, e], r]) => { | ||
@@ -40,0 +39,0 @@ const mabs = abs(m); |
@@ -1,3 +0,2 @@ | ||
import * as _ from "./module.f.js"; | ||
const { decToBin } = _; | ||
import { decToBin } from "./module.f.js"; | ||
export default { | ||
@@ -4,0 +3,0 @@ decToBin: [ |
import * as compare from '../function/compare/module.f.ts'; | ||
import * as Operator from '../function/operator/module.f.ts'; | ||
import type * as Operator from '../function/operator/module.f.ts'; | ||
import { type List } from '../list/module.f.ts'; | ||
export declare const addition: (a: bigint) => (b: bigint) => bigint; | ||
type Unary = Operator.Unary<bigint, bigint>; | ||
type Reduce = Operator.Reduce<bigint>; | ||
export declare const addition: Reduce; | ||
export declare const sum: (input: List<bigint>) => bigint; | ||
export declare const abs: (a: bigint) => bigint; | ||
export declare const abs: Unary; | ||
export declare const sign: (a: bigint) => compare.Sign; | ||
export declare const serialize: (a: bigint) => string; | ||
type Additive<T> = { | ||
readonly 0: T; | ||
readonly add: Operator.Reduce<T>; | ||
}; | ||
export declare const scalar_mul: <T>(a: Additive<T>) => (a: T) => (n: bigint) => T; | ||
/** | ||
@@ -15,0 +12,0 @@ * Calculates the base-2 logarithm (floor). |
import * as compare from "../function/compare/module.f.js"; | ||
import * as Operator from "../function/operator/module.f.js"; | ||
const { unsafeCmp } = compare; | ||
@@ -10,17 +9,2 @@ import { reduce } from "../list/module.f.js"; | ||
export const serialize = a => `${a}n`; | ||
export const scalar_mul = ({ 0: _0, add }) => a => n => { | ||
let ai = a; | ||
let ni = n; | ||
let result = _0; | ||
while (true) { | ||
if ((ni & 1n) === 1n) { | ||
result = add(result)(ai); | ||
} | ||
ni >>= 1n; | ||
if (ni === 0n) { | ||
return result; | ||
} | ||
ai = add(ai)(ai); | ||
} | ||
}; | ||
/** | ||
@@ -27,0 +11,0 @@ * Calculates the base-2 logarithm (floor). |
521792
245
14364