Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/typical/strnum.ts>AddDigit

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
type alias AddDigit
import { type AddDigit } from "https://deno.land/x/rimbu@0.13.5/typical/strnum.ts";

Given two string digits, this type returns a tuple of which the first element is the digit resulting from addition of the two digits, and the second element is a boolean indicating whether there was an overflow.

Examples

Example 1

AddDigit<'1', '2'> => ['3', false]
AddDigit<'8', '4'> => ['2', true]

Type Parameters

D1 extends Digit
D2 extends Digit
definition: D1 extends "0" ? [D2, false] : D2 extends "0" ? [D1, false] : [D1, D2] extends
| SymTup<"1", "9">
| SymTup<"2", "8">
| SymTup<"3", "7">
| SymTup<"4", "6">
| "5"[]
? ["0", true] : [D1, D2] extends
| SymTup<"2", "9">
| SymTup<"3", "8">
| SymTup<"4", "7">
| SymTup<"5", "6">
? ["1", true] : [D1, D2] extends "1"[] ? ["2", false] : [D1, D2] extends
| SymTup<"3", "9">
| SymTup<"4", "8">
| SymTup<"5", "7">
| "6"[]
? ["2", true] : [D1, D2] extends SymTup<"1", "2"> ? ["3", false] : [D1, D2] extends SymTup<"4", "9"> | SymTup<"5", "8"> | SymTup<"6", "7"> ? ["3", true] : [D1, D2] extends SymTup<"1", "3"> | "2"[] ? ["4", false] : [D1, D2] extends SymTup<"5", "9"> | SymTup<"6", "8"> | "7"[] ? ["4", true] : [D1, D2] extends SymTup<"1", "4"> | SymTup<"2", "3"> ? ["5", false] : [D1, D2] extends SymTup<"6", "9"> | SymTup<"7", "8"> ? ["5", true] : [D1, D2] extends SymTup<"1", "5"> | SymTup<"2", "4"> | "3"[] ? ["6", false] : [D1, D2] extends SymTup<"7", "9"> | "8"[] ? ["6", true] : [D1, D2] extends SymTup<"1", "6"> | SymTup<"2", "5"> | SymTup<"3", "4"> ? ["7", false] : [D1, D2] extends SymTup<"8", "9"> ? ["7", true] : [D1, D2] extends
| SymTup<"1", "7">
| SymTup<"2", "6">
| SymTup<"3", "5">
| "4"[]
? ["8", false] : [D1, D2] extends "9"[] ? ["8", true] : [D1, D2] extends
| SymTup<"1", "8">
| SymTup<"2", "7">
| SymTup<"3", "6">
| SymTup<"4", "5">
? ["9", false] : never