functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
27 lines (26 loc) • 855 B
JavaScript
/**
* Utility functions for working with strings and lists of strings.
*
* @module
*
* @example
*
* ```js
* import { join, concat, repeat, cmp } from './module.f.ts'
*
* const words = ['hello', 'world']
* join(' ')(words) // 'hello world'
* concat(words) // 'helloworld'
* repeat('abc')(3) // 'abcabcabc'
* cmp('apple')('banana') // -1
* ```
*/
import { reduce as listReduce, repeat as listRepeat } from "../list/module.f.js";
import { compose } from "../function/module.f.js";
import { unsafeCmp } from "../function/compare/module.f.js";
import { join as joinOp, concat as concatOp } from "../function/operator/module.f.js";
const reduce = o => listReduce(o)('');
export const join = compose(joinOp)(reduce);
export const concat = reduce(concatOp);
export const repeat = v => compose(listRepeat(v))(concat);
export const cmp = unsafeCmp;