restructure code a bit, add comparison functions for primitive types and composed types (needed to put values in sets)

This commit is contained in:
Joeri Exelmans 2025-04-17 15:11:06 +02:00
parent 3978f7f835
commit 8653bb99c6
12 changed files with 175 additions and 64 deletions

View file

@ -6,12 +6,20 @@ import { lsType } from "./types.js";
import { Typed } from "../typed.js"
// 'normal' implementation
const emptyList = {l:[]};
export const emptyList = {l:[]};
const emptyListType = makeGeneric(a => lsType(a));
const get = ls => i => ls.l[i];
const put = ls => i => elem => ({l: ls.l.with(Number(i), elem)});
const push = ls => elem => ({l:ls.l.concat([elem])});
const map = ls => fn => ({ l: ls.l.map(elem => fn(elem)) });
export const get = ls => i => ls.l[i];
export const put = ls => i => elem => ({l: ls.l.with(Number(i), elem)});
export const push = ls => elem => ({l:ls.l.concat([elem])});
export const map = ls => fn => ({ l: ls.l.map(elem => fn(elem)) });
export const length = ls => ls.l.length;
export const fold = ls => callback => initial => {
let acc = initial;
for (let i=0; i<ls.l.length; i++) {
acc = callback(acc)(ls.l[i]);
}
return acc;
}
export const String = lsType(Char); // alias
export const Module = lsType(Typed);