Skip to main content
Module

x/froebel/nullishChain.ts>asyncNullishChain

A strictly typed utility library.
Go to Latest
variable asyncNullishChain
import { asyncNullishChain } from "https://deno.land/x/froebel@v0.21.0/nullishChain.ts";

Same as nullishChain but accept asynchronous functions too.

Examples

Example 1

const readFromCache = (id: string): Resource => { if (id in cache) return cache[id] }
const readFromFile  = (id: string): Resource => { if (fileExists(id)) return readFile(id) }
const fetchFromNet  = async (id: string): Promise<Resource> => await fetch(`someURL/${id}`)

// async (id: string) => Promise<Resource>
const getResource = asyncNullishChain(readFromCache, readFromFile, fetchFromNet)

type

<FF extends λ, FR extends λ<Parameters<FF>>[]>(...unnamed 0: [FF, ...FR] | []) => unknown