functionalscript
Advanced tools
Comparing version 0.3.1 to 0.3.2
{ | ||
"name": "@functionalscript/functionalscript", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"license": "AGPL-3.0-only", | ||
@@ -5,0 +5,0 @@ "exports": { |
import * as operator from '../types/function/operator/module.f.ts' | ||
import * as rangeMap from '../types/range_map/module.f.ts' | ||
const { merge: rangeMapMerge, fromRange, get } = rangeMap | ||
import { | ||
merge as rangeMapMerge, | ||
fromRange, | ||
get, | ||
type RangeMapArray, | ||
type RangeMerge, | ||
} from '../types/range_map/module.f.ts' | ||
import * as list from '../types/list/module.f.ts' | ||
const { reduce: listReduce } = list | ||
import * as ascii from '../text/ascii/module.f.ts' | ||
const { range: asciiRange } = ascii | ||
const { fromCharCode } = String | ||
import * as f from '../types/function/module.f.ts' | ||
const { fn } = f | ||
import * as _range from '../types/range/module.f.ts' | ||
const { one } = _range | ||
import { range as asciiRange } from '../text/ascii/module.f.ts' | ||
import { fn } from '../types/function/module.f.ts' | ||
import { one, type Range } from '../types/range/module.f.ts' | ||
const { toArray, map } = list | ||
const fromCharCode = String.fromCharCode | ||
type Result = readonly[readonly string[], ToResult] | ||
@@ -21,3 +24,3 @@ | ||
type State<T> = rangeMap.RangeMapArray<CreateToResult<T>> | ||
type State<T> = RangeMapArray<CreateToResult<T>> | ||
@@ -46,4 +49,4 @@ const unexpectedSymbol | ||
const merge | ||
: rangeMap.RangeMerge<CreateToResult<T>> | ||
= rangeMapMerge({ | ||
: RangeMerge<CreateToResult<T>> | ||
= rangeMapMerge({ | ||
union, | ||
@@ -60,9 +63,12 @@ equal: operator.strictEqual, | ||
const rangeSet | ||
= (l: readonly string[]) => <T>(f: CreateToResult<T>): State<T> => { | ||
= (l: readonly string[]) => <T>(f: CreateToResult<T>): State<T> => { | ||
const codePointRange | ||
: (a: _range.Range) => (f: CreateToResult<T>) => State<T> | ||
= fromRange(def) | ||
: (a: Range) => (f: CreateToResult<T>) => State<T> | ||
= fromRange(def) | ||
const g | ||
: (r: string) => State<T> | ||
= r => codePointRange(asciiRange(r))(f) | ||
: (r: string) => State<T> | ||
= r => codePointRange(asciiRange(r))(f) | ||
return reduce(map(g)(l)) | ||
@@ -69,0 +75,0 @@ } |
@@ -1,8 +0,5 @@ | ||
import * as list from '../types/list/module.f.ts' | ||
const { map, flatMap, flat, concat: listConcat } = list | ||
import * as s from '../types/string/module.f.ts' | ||
const { concat: stringConcat } = s | ||
import { map, flatMap, flat, concat as listConcat, type List } from '../types/list/module.f.ts' | ||
import { concat as stringConcat } from '../types/string/module.f.ts' | ||
import * as O from '../types/object/module.f.ts' | ||
import * as f from '../types/function/module.f.ts' | ||
const { compose } = f | ||
import { compose } from '../types/function/module.f.ts' | ||
import * as utf16 from '../text/utf16/module.f.ts' | ||
@@ -75,4 +72,4 @@ const { stringToList } = utf16 | ||
const node | ||
: (n: Node) => list.List<string> | ||
= n => typeof n === 'string' ? escape(n) : element(n) | ||
: (n: Node) => List<string> | ||
= n => typeof n === 'string' ? escape(n) : element(n) | ||
@@ -82,16 +79,16 @@ const nodes = flatMap(node) | ||
const attribute | ||
: (a: O.Entry<string>) => list.List<string> | ||
= ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']]) | ||
: (a: O.Entry<string>) => List<string> | ||
= ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']]) | ||
const attributes | ||
: (a: Attributes) => list.List<string> | ||
= compose(entries)(flatMap(attribute)) | ||
: (a: Attributes) => List<string> | ||
= compose(entries)(flatMap(attribute)) | ||
const open | ||
: (t: string) => (a: Attributes) => list.List<string> | ||
= t => a => flat([[`<`, t], attributes(a), [`>`]]) | ||
: (t: string) => (a: Attributes) => List<string> | ||
= t => a => flat([[`<`, t], attributes(a), [`>`]]) | ||
const element3 | ||
: (t: string) => (an: readonly[Attributes, readonly Node[]]) => list.List<string> | ||
= t => ([a, n]) => { | ||
: (t: string) => (an: readonly[Attributes, readonly Node[]]) => List<string> | ||
= t => ([a, n]) => { | ||
const o = flat([[`<`, t], attributes(a), [`>`]]) | ||
@@ -102,4 +99,4 @@ return isVoid(t) ? o : flat([o, nodes(n), ['</', t, '>']]) | ||
export const element | ||
: (element: Element) => list.List<string> | ||
= e => { | ||
: (element: Element) => List<string> | ||
= e => { | ||
const [t, a, ...n] = e | ||
@@ -106,0 +103,0 @@ return element3(t)(a === undefined ? [{}, []]: typeof a === 'object' && !(a instanceof Array) ? [a, n] : [{}, [a, ...n]]) |
{ | ||
"name": "functionalscript", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "FunctionalScript is a functional subset of JavaScript", |
@@ -1,8 +0,15 @@ | ||
import * as list from '../../types/list/module.f.ts' | ||
import { | ||
map, | ||
flat, | ||
stateScan, | ||
reduce, | ||
flatMap, | ||
empty, | ||
type List, | ||
type Result, | ||
} from '../../types/list/module.f.ts' | ||
import * as operator from '../../types/function/operator/module.f.ts' | ||
import * as range from '../../types/range/module.f.ts' | ||
const { contains } = range | ||
import { contains } from '../../types/range/module.f.ts' | ||
import * as f from '../../types/function/module.f.ts' | ||
const { fn } = f | ||
const { map, flat, stateScan, reduce, flatMap, empty } = list | ||
@@ -39,4 +46,4 @@ type WordOrEof = u16|null | ||
const codePointToUtf16 | ||
: (input: i32) => list.List<u16> | ||
= codePoint => { | ||
: (input: i32) => List<u16> | ||
= codePoint => { | ||
if (isBmpCodePoint(codePoint)) { return [codePoint] } | ||
@@ -57,4 +64,4 @@ if (isSupplementaryPlane(codePoint)) { | ||
const utf16ByteToCodePointOp | ||
: operator.StateScan<u16, Utf16State, list.List<i32>> | ||
= state => word => { | ||
: operator.StateScan<u16, Utf16State, List<i32>> | ||
= state => word => { | ||
if (!u16(word)) { | ||
@@ -79,23 +86,23 @@ return [[0xffffffff], state] | ||
const utf16EofToCodePointOp | ||
: (state: Utf16State) => readonly[list.List<i32>, Utf16State] | ||
= state => [state === null ? empty : [state | errorMask], null] | ||
: (state: Utf16State) => readonly[List<i32>, Utf16State] | ||
= state => [state === null ? empty : [state | errorMask], null] | ||
const utf16ByteOrEofToCodePointOp | ||
: operator.StateScan<WordOrEof, Utf16State, list.List<i32>> | ||
= state => input => input === null ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input) | ||
: operator.StateScan<WordOrEof, Utf16State, List<i32>> | ||
= state => input => input === null ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input) | ||
const eofList | ||
: list.List<WordOrEof> | ||
= [null] | ||
: List<WordOrEof> | ||
= [null] | ||
export const toCodePointList | ||
: (input: list.List<u16>) => list.List<i32> | ||
= input => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList]))) | ||
: (input: List<u16>) => List<i32> | ||
= input => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList]))) | ||
export const stringToList | ||
: (s: string) => list.List<u16> | ||
= s => { | ||
: (s: string) => List<u16> | ||
= s => { | ||
const at | ||
: (i: number) => list.Result<number> | ||
= i => { | ||
: (i: number) => Result<number> | ||
= i => { | ||
const first = s.charCodeAt(i) | ||
@@ -108,5 +115,5 @@ return isNaN(first) ? empty : { first, tail: () => at(i + 1) } | ||
export const listToString | ||
: (input: list.List<u16>) => string | ||
= fn(map(String.fromCharCode)) | ||
: (input: List<u16>) => string | ||
= fn(map(String.fromCharCode)) | ||
.then(reduce(operator.concat)('')) | ||
.result |
@@ -1,5 +0,4 @@ | ||
import * as list from '../../types/list/module.f.ts' | ||
import { flatMap, flat, stateScan, type List } from '../../types/list/module.f.ts' | ||
import * as operator from '../../types/function/operator/module.f.ts' | ||
import * as Array from '../../types/array/module.f.ts' | ||
const { flatMap, flat, stateScan } = list | ||
@@ -19,3 +18,3 @@ type ByteOrEof = u8|null | ||
const codePointToUtf8 | ||
: (input:number) => list.List<u8> | ||
: (input:number) => List<u8> | ||
= input => { | ||
@@ -65,3 +64,3 @@ if (input >= 0x0000 && input <= 0x007f) { return [input & 0b01111_1111] } | ||
const utf8ByteToCodePointOp | ||
: operator.StateScan<number, Utf8State, list.List<i32>> | ||
: operator.StateScan<number, Utf8State, List<i32>> | ||
= state => byte => { | ||
@@ -103,16 +102,16 @@ if (byte < 0x00 || byte > 0xff) { | ||
const utf8EofToCodePointOp | ||
: (state: Utf8State) => readonly[list.List<i32>, Utf8State] | ||
= state => | ||
: (state: Utf8State) => readonly[List<i32>, Utf8State] | ||
= state => | ||
[state === null ? null : [utf8StateToError(state)], null] | ||
const utf8ByteOrEofToCodePointOp | ||
: operator.StateScan<ByteOrEof, Utf8State, list.List<i32>> | ||
= state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input) | ||
: operator.StateScan<ByteOrEof, Utf8State, List<i32>> | ||
= state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input) | ||
const eofList | ||
: list.List<ByteOrEof> | ||
= [null] | ||
: List<ByteOrEof> | ||
= [null] | ||
export const toCodePointList | ||
: (input: list.List<u8>) => list.List<i32> | ||
= input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList]))) | ||
: (input: List<u8>) => List<i32> | ||
= input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList]))) |
import * as compare from '../function/compare/module.f.ts' | ||
import * as Operator from '../function/operator/module.f.ts' | ||
const { unsafeCmp } = compare | ||
import * as list from '../list/module.f.ts' | ||
const { reduce } = list | ||
import { reduce } from '../list/module.f.ts' | ||
@@ -7,0 +6,0 @@ type Unary = Operator.Unary<bigint, bigint> |
@@ -1,3 +0,2 @@ | ||
import * as f from '../function/module.f.ts' | ||
const { compose } = f | ||
import { compose } from '../function/module.f.ts' | ||
import * as RangeMap from '../range_map/module.f.ts' | ||
@@ -4,0 +3,0 @@ import * as SortedSet from '../sorted_set/module.f.ts' |
@@ -1,5 +0,3 @@ | ||
import * as function_ from '../function/module.f.ts' | ||
const { identity, fn, compose } = function_ | ||
import * as operator from '../function/operator/module.f.ts' | ||
const { | ||
import { identity, fn, compose } from '../function/module.f.ts' | ||
import { | ||
addition, | ||
@@ -10,4 +8,9 @@ logicalNot, | ||
foldToScan, | ||
reduceToScan | ||
} = operator | ||
reduceToScan, | ||
type Scan, | ||
type StateScan, | ||
type Fold, | ||
type Reduce, | ||
type Equal, | ||
} from '../function/operator/module.f.ts' | ||
@@ -252,3 +255,3 @@ export type List<T> = NotLazy<T> | Thunk<T> | ||
const scanStep | ||
: <I, O>(op: operator.Scan<I, O>) => (ne: NonEmpty<I>) => List<O> | ||
: <I, O>(op: Scan<I, O>) => (ne: NonEmpty<I>) => List<O> | ||
= op => ne => { | ||
@@ -260,19 +263,19 @@ const [first, newOp] = op(ne.first) | ||
export const scan | ||
: <I, O>(op: operator.Scan<I, O>) => (input: List<I>) => Thunk<O> | ||
: <I, O>(op: Scan<I, O>) => (input: List<I>) => Thunk<O> | ||
= op => apply(scanStep(op)) | ||
export const stateScan | ||
: <I, S, O>(op: operator.StateScan<I, S, O>) => (init: S) => (input: List<I>) => Thunk<O> | ||
: <I, S, O>(op: StateScan<I, S, O>) => (init: S) => (input: List<I>) => Thunk<O> | ||
= op => compose(stateScanToScan(op))(scan) | ||
export const foldScan | ||
: <I,O>(op: operator.Fold<I, O>) => (init: O) => (input: List<I>) => Thunk<O> | ||
: <I,O>(op: Fold<I, O>) => (init: O) => (input: List<I>) => Thunk<O> | ||
= op => compose(foldToScan(op))(scan) | ||
export const fold | ||
: <I,O>(op: operator.Fold<I, O>) => (init: O) => (input: List<I>) => O | ||
: <I,O>(op: Fold<I, O>) => (init: O) => (input: List<I>) => O | ||
= op => init => compose(foldScan(op)(init))(last(init)) | ||
export const reduce | ||
: <T>(op: operator.Reduce<T>) => <D>(def: D) => (input: List<T>) => D|T | ||
: <T>(op: Reduce<T>) => <D>(def: D) => (input: List<T>) => D|T | ||
= op => def => compose(scan(reduceToScan(op)))(last(def)) | ||
@@ -310,3 +313,3 @@ | ||
const o | ||
: operator.StateScan<T, number, Entry<T>> | ||
: StateScan<T, number, Entry<T>> | ||
= entryOperator | ||
@@ -335,5 +338,5 @@ return stateScan(o)(0)(input) | ||
export const equal | ||
: <T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean | ||
: <T>(e: Equal<T>) => (a: List<T>) => (b: List<T>) => boolean | ||
= e => { | ||
type T = typeof e extends operator.Equal<infer T> ? T : never | ||
type T = typeof e extends Equal<infer T> ? T : never | ||
const f | ||
@@ -340,0 +343,0 @@ : (a: List<T>) => (b: List<T>) => List<boolean> |
@@ -1,5 +0,3 @@ | ||
import * as list from '../list/module.f.ts' | ||
const { reduce } = list | ||
import * as operator from '../function/operator/module.f.ts' | ||
const { addition, min: minOp, max: maxOp } = operator | ||
import { reduce } from '../list/module.f.ts' | ||
import { addition, min as minOp, max as maxOp } from '../function/operator/module.f.ts' | ||
import * as compare from '../function/compare/module.f.ts' | ||
@@ -6,0 +4,0 @@ const { unsafeCmp } = compare |
@@ -9,13 +9,11 @@ import * as BtreeTypes from '../btree/types/module.f.ts' | ||
const { set: btreeSet } = bts | ||
export const { | ||
values, | ||
empty, | ||
}: { values: (s: StringSet) => list.List<string>, empty: null } = btree | ||
import * as string from "../string/module.f.ts" | ||
const { cmp } = string | ||
import * as list from '../list/module.f.ts' | ||
const { fold } = list | ||
import { fold, type List } from '../list/module.f.ts' | ||
import * as f from '../function/module.f.ts' | ||
const { compose } = f | ||
export const values: (s: StringSet) => List<string> = btree.values | ||
export const empty: null = btree.empty | ||
export type StringSet = BtreeTypes.Tree<string> | ||
@@ -22,0 +20,0 @@ |
import * as list from '../list/module.f.ts' | ||
const { reduce: listReduce, repeat: listRepeat } = list | ||
import * as f from '../function/module.f.ts' | ||
const { compose } = f | ||
import { compose } from '../function/module.f.ts' | ||
import * as compare from '../function/compare/module.f.ts' | ||
const { unsafeCmp } = compare | ||
import * as op from '../function/operator/module.f.ts' | ||
const { join: joinOp, concat: concatOp } = op | ||
import { join as joinOp, concat as concatOp, type Reduce } from '../function/operator/module.f.ts' | ||
const reduce | ||
: (o: op.Reduce<string>) => (input: list.List<string>) => string | ||
: (o: Reduce<string>) => (input: list.List<string>) => string | ||
= o => listReduce(o)('') | ||
@@ -13,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
664548
12696