UNPKG

hkt-toolbelt

Version:

Functional and composable type utilities

17 lines (16 loc) 976 B
import { $, Combinator, Conditional, Function, NaturalNumberTheory } from '..'; /** * `CollatzSequence` is a type-level function that represents the Collatz sequence. * This is a sequence of numbers generated by repeatedly applying the Collatz function, * starting from a given number, until reaching 1. This sequence is generated using the FixSequence type-level function, * which creates a fixed-point sequence for the Collatz function until it reaches a fixed point, which in this case is 1. * * Note: We're "artificially" making `Collatz(1)` return `1` so that we can use the fixed sequence operation. * * @template T - The starting number of the sequence. * * @example * type T0 = $<CollatzSequence, 6> // [6, 3, 10, 5, 16, 8, 4, 2, 1] * type T1 = $<CollatzSequence, 5> // [5, 16, 8, 4, 2, 1] */ export type CollatzSequence = $<Combinator.FixSequence, $<$<$<Conditional.If, $<Conditional.Equals, 1>>, $<Function.Constant, 1>>, NaturalNumberTheory.Collatz>>;