Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

struct

import { struct } from "https://raw.githubusercontent.com/baetheus/fun/main/combinable.ts";

Get a Combinable from a struct of combinables. The resulting combinable will operate over similar shaped structs applying the input combinables applying each based on its position,

@example
import type { Combinable } from "./combinable.ts";
import * as SG from "./combinable.ts";
import * as N from "./number.ts";
import { pipe } from "./fn.ts";

type Person = { name: string, age: number };
const person = (name: string, age: number): Person => ({ name, age });

// Chooses the longest string, defaulting to left when equal
const longestString: Combinable<string> = {
  combine: (right) => (left) => right.length > left.length ? right : left,
};

// This combinable will merge two people, choosing the longest
// name and the oldest age
const { combine } = SG.struct<Person>({
  name: longestString,
  age: N.InitializableNumberMax,
})

const brandon = pipe(
  person("Brandon Blaylock", 12),
  combine(person("Bdon", 17)),
  combine(person("Brandon", 30))
); // brandon === { name: "Brandon Blaylock", age: 30 }
function struct<O extends ReadonlyRecord<any>>(combinables: [K in keyof O]: Combinable<O[K]>): Combinable<O>;
§
struct<O extends ReadonlyRecord<any>>(combinables: [K in keyof O]: Combinable<O[K]>): Combinable<O>
[src]

§Type Parameters

§
O extends ReadonlyRecord<any>
[src]

§Parameters

§
combinables: [K in keyof O]: Combinable<O[K]>
[src]

§Return Type