diff --git a/.changeset/dry-bugs-brake.md b/.changeset/dry-bugs-brake.md new file mode 100644 index 0000000..0505938 --- /dev/null +++ b/.changeset/dry-bugs-brake.md @@ -0,0 +1,5 @@ +--- +"any-ts": patch +--- + +fix: moves `array` member declar… Andrew Jarrett 1 minute diff --git a/src/array/array.ts b/src/array/array.ts index ff027fe..d97a7f5 100644 --- a/src/array/array.ts +++ b/src/array/array.ts @@ -24,6 +24,8 @@ export declare namespace array { finiteOf, head, heads, + last, + lead, nonfinite, nonfiniteOf, snd, @@ -39,6 +41,34 @@ export declare namespace array { // types containing types tupleN, } + + type finite = check.is.tuple + type finiteOf = check.is.tuple + type nonfinite + = never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? any.array : never : never) + type nonfiniteOf + = never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? invariant : never : never) + /** {@link fst `array.fst`} is an alias for {@link head `array.head`} */ + + type fst = never | head + /** {@link head `array.head`} returns just the _first_ element of an array */ + type head + = [xs] extends [nonempty.array] ? head : (undefined | xs[number]) + /** {@link heads `array.heads`} returns just the _first_ item of _every_ element of a matrix (an array of arrays) */ + type heads> = never | { [ix in keyof xss]: xss[ix][0] } + /** {@link snd `array.snd`} returns just the _second_ element of an array */ + type snd = never | head> + /** {@link snds `array.snds`} returns just the _second_ item of _every_ element of a matrix (an array of arrays) */ + type snds> = never | { [ix in keyof xss]: xss[ix][1] } + /** {@link tail `array.tail`} returns every element _but_ the _first_ element of an array */ + type tail = xs extends [any, ...infer tail] ? tail : never + /** {@link tail `array.tail`} returns every element _but_ the _first_ element of _every_ element of a matrix (an array of arrays) */ + type tails> = never | { [ix in keyof xss]: tail } + + /** {@link last `array.last`} returns _just_ every element _but_ the _last_ element of an array */ + type last = xs extends [infer last, any] ? last : never + /** {@link lead `array.lead`} returns every element _but_ the _last_ element of an array */ + type lead = xs extends [...infer lead, any] ? lead : never } export declare namespace nonemptyArray { @@ -65,26 +95,3 @@ export declare namespace nonemptyArray { : never : never } - -type finite = check.is.tuple -type finiteOf = check.is.tuple -type nonfinite - = never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? any.array : never : never) -type nonfiniteOf - = never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? invariant : never : never) - -/** - * {@link fst `array.fst`} is an alias for {@link head `array.head`} - */ -type fst = never | head - -type head - = [xs] extends [nonempty.array] ? head : (undefined | xs[number]) - -type heads> = never | { [ix in keyof xss]: xss[ix][0] } - -type snd = never | head> -type snds> = never | { [ix in keyof xss]: xss[ix][1] } - -type tail = xs extends [any, ...infer tail] ? tail : never -type tails> = never | { [ix in keyof xss]: tail }