Skip to main content
Module

x/fun/mod.ts>json_schema.intersect

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

Creates a JsonBuilder that intersects two JsonBuilders

Examples

Example 1

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

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

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

Returns

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