Skip to main content
Module

x/fun/json_schema.ts>union

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function union
import { union } from "https://deno.land/x/fun@v2.0.0/json_schema.ts";

Creates a JsonBuilder that unions two JsonBuilders

Examples

Example 1

import * as J from "./json_schema.ts";
import { pipe } from "./fn.ts";

// {
//   "anyOf": [
//     {
//       "type": "object",
//       "properties": {
//         "num": {
//           "type": "number"
//         }
//       },
//       "required": [
//         "num"
//       ]
//     },
//     {
//       "type": "object",
//       "properties": {
//         "str": {
//           "type": "string"
//         }
//       }
//     }
//   ]
// }

const schema = pipe(
  J.struct({ num: J.number() }),
  J.union(J.partial({ str: J.string() })),
  J.print,
);

Returns

<A>(ta: JsonBuilder<A>) => JsonBuilder<A & I>