diff --git a/examples/enum.js b/examples/enum.js deleted file mode 100644 index 2bb94bd..0000000 --- a/examples/enum.js +++ /dev/null @@ -1,52 +0,0 @@ -import { makeCompareFn } from "../lib/compare/dynamic.js"; -import { Int, Unit } from "../lib/primitives/primitive_types.js"; -import { unit } from "../lib/primitives/unit.js"; -import { makeConstructors, makeMatchFn } from "../lib/structures/enum.js"; -import { enumType } from "../lib/structures/enum.types.js"; -import { newProduct } from "../lib/structures/product.js"; -import { lsType } from "../lib/structures/type_constructors.types.js"; -import { prettyT } from "../lib/util/pretty.js"; - -Error.stackTraceLimit = Infinity; - -const variants = [ - newProduct("price")(_ => Int), - newProduct("prices")(_ => lsType(_ => Int)), - newProduct("not_found")(_ => Unit), -]; - -const structuralType = enumType(variants); - -console.log("observe the type that was generated:"); -console.log(" ", prettyT(structuralType)); - -const [newPrice, newPrices, newNotFound] = makeConstructors(variants); - -const price = newPrice(10); -const prices = newPrices([20, 30]); -const notFound = newNotFound(unit); - -console.log("observe the encoding of different variant instances:"); -console.log(" ", price); -console.log(" ", prices); -console.log(" ", notFound); - -const myEnumToString = x => makeMatchFn(variants)(x) - (price => `Price: ${price}`) - (prices => `Prices: ${prices}`) - (() => "Not found!"); - -console.log("observe the generated match function in action:"); -console.log(" ", myEnumToString(price)); -console.log(" ", myEnumToString(prices)); -console.log(" ", myEnumToString(notFound)); - -const compareMyEnum = makeCompareFn(structuralType); - -console.log("observe the generated compare function in action:"); -console.log(" should be smaller ->", compareMyEnum(price)(prices)); -console.log(" should be bigger ->", compareMyEnum(prices)(price)); -console.log(" should be bigger ->", compareMyEnum(notFound)(price)); -console.log(" should be equal ->", compareMyEnum(prices)(prices)); -console.log(" should be smaller ->", compareMyEnum(newPrice(5))(newPrice(6))); -console.log(" should be bigger ->", compareMyEnum(newPrices([5, 6]))(newPrices([5, 5]))); diff --git a/snippets/README.txt b/snippets/README.txt new file mode 100644 index 0000000..22d6333 --- /dev/null +++ b/snippets/README.txt @@ -0,0 +1 @@ +In this directory, just some scripts I wrote to get my hands dirty. \ No newline at end of file diff --git a/examples/rbtree.js b/snippets/rbtree.js similarity index 100% rename from examples/rbtree.js rename to snippets/rbtree.js diff --git a/examples/versioning.js b/snippets/versioning.js similarity index 100% rename from examples/versioning.js rename to snippets/versioning.js