functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
28 lines (27 loc) • 692 B
JavaScript
import { repeat } from "./module.f.js";
export default {
numberAdd: () => {
const add = {
identity: 0,
operation: a => b => a + b,
};
const resultAdd = repeat(add)(2)(10n); // 20
if (resultAdd !== 20) {
throw resultAdd;
}
const id = repeat(add)(42)(0n);
if (id !== 0) {
throw id;
}
},
stringConcat: () => {
const concat = {
identity: '',
operation: a => b => a + b,
};
const resultConcat = repeat(concat)('ha')(3n); // 'hahaha'
if (resultConcat !== 'hahaha') {
throw resultConcat;
}
}
};