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

match

import { match } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/datum.ts";

Pattern match on a Datum to extract values.

@example
import { match, initial, pending, refresh, replete } from "./datum.ts";

const matcher = match(
  () => "Not started",
  () => "Loading...",
  (value) => `Fresh: ${value}`,
  (value) => `Stale: ${value}`
);

console.log(matcher(initial)); // "Not started"
console.log(matcher(pending)); // "Loading..."
console.log(matcher(refresh("data"))); // "Stale: data"
console.log(matcher(replete("data"))); // "Fresh: data"
function match<A, B>(
onInitial: () => B,
onPending: () => B,
onReplete: (a: A) => B,
onRefresh: (a: A) => B,
): (ua: Datum<A>) => B;
§
match<A, B>(onInitial: () => B, onPending: () => B, onReplete: (a: A) => B, onRefresh: (a: A) => B): (ua: Datum<A>) => B
[src]

§Type Parameters

§Parameters

§
onInitial: () => B
[src]
§
onPending: () => B
[src]
§
onReplete: (a: A) => B
[src]
§
onRefresh: (a: A) => B
[src]

§Return Type

§
(ua: Datum<A>) => B
[src]