import { type StrNum } from "https://deno.land/x/rimbu@1.1.0/typical/index.ts";
const { Subtract } = StrNum;
Returns the result of subtracting the second from the first given string-number, or never if the second value is greater than the first. (Only natural numbers currently supported)
Examples
Example 1
Example 1
SSubtract<'13', '8'> => '5'
SSubtract<'5371', '139'> => '5232'
SSubtract<'100', '101'> => never
definition: N1 extends N2 ? "0" : N1 extends Str.Append<infer N1Start, Digit> ? N2 extends Str.Append<infer N2Start, Digit> ? N1 extends Str.Append<N1Start, infer N1LastDigit> ? N2 extends Str.Append<N2Start, infer N2LastDigit> ? SubDigit<Digit & N1LastDigit, Digit & N2LastDigit> extends [infer NewDigit, infer Underflow] ? Underflow extends true ? N1Start extends "" ? never : Subtract<Subtract<N1Start, N2Start>, "1"> extends infer Start ? Start extends "0" ? Digit & NewDigit : Str.Append<string & Start, Digit & NewDigit> : never : Subtract<N1Start, N2Start> extends infer Start ? Start extends "0" ? Digit & NewDigit : Str.Append<string & Start, Digit & NewDigit> : never : never : never : never : N1 : never