reorganize directory and file structure
This commit is contained in:
parent
1d826ea8d4
commit
48390b8556
99 changed files with 1155 additions and 1629 deletions
33
lib/structures/struct.js
Normal file
33
lib/structures/struct.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { unit } from "../primitives/unit.js";
|
||||
import { capitalizeFirstLetter } from "../util/util.js";
|
||||
import { newProduct, getLeft, getRight } from "./product.js";
|
||||
|
||||
export const makeConstructor = nParams => {
|
||||
const internal = (nParams, ret) => {
|
||||
if (nParams === 0) {
|
||||
const result = ret(unit);
|
||||
return result;
|
||||
}
|
||||
return nextParam => {
|
||||
const wrappedName = 'wrapped_' + ret.name;
|
||||
const newRet = {
|
||||
[wrappedName]: inner => newProduct(nextParam)(ret(inner)),
|
||||
}[wrappedName];
|
||||
return internal(nParams-1, newRet);
|
||||
}
|
||||
};
|
||||
const id = x => x;
|
||||
return internal(nParams, id);
|
||||
};
|
||||
|
||||
export const makeGetters = fieldNames => {
|
||||
if (fieldNames.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const [fieldName, ...rest] = fieldNames;
|
||||
const getterName = `get${capitalizeFirstLetter(fieldName)}`;
|
||||
return [
|
||||
{ [getterName]: obj => getLeft(obj) }[getterName],
|
||||
...makeGetters(rest).map(getter => ({[getter.name]: obj => getter(getRight(obj))}[getter.name])),
|
||||
];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue