UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

25 lines (22 loc) • 662 B
import type { List } from "."; import type { FoldL } from "./FoldL"; import type { Args, Fn } from "../HKT"; import type { Int } from "../Num"; import type AddFn from "../Num/Int/Add"; import type { AssertInt } from "../helpers"; /** * Calculate the sum of a {@link List} of {@link Int}s. * * Sig: `(ns: List<Int>) => Int` */ export type Sum<NS extends List<Int>> = AssertInt< FoldL<AddFn, 0, NS> extends infer R extends Int ? R : never >; /** * [Fn] Calculate the sum of a {@link List} of {@link Int}s. * * Sig: `(ns: List<Int>) => Int` */ export default interface SumFn extends Fn<[List<Int>], Int> { def: ([ns]: Args<this>) => Sum<typeof ns>; }