Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: moves array module declarations into the array namespace proper #106

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-bugs-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"any-ts": patch
---

fix: moves `array` member declar… Andrew Jarrett 1 minute
53 changes: 30 additions & 23 deletions src/array/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export declare namespace array {
finiteOf,
head,
heads,
last,
lead,
nonfinite,
nonfiniteOf,
snd,
Expand All @@ -39,6 +41,34 @@ export declare namespace array {
// types containing types
tupleN,
}

type finite<xs> = check.is.tuple<xs, any.array, "hush">
type finiteOf<xs, invariant extends any.array> = check.is.tuple<xs, invariant, "hush">
type nonfinite<xs>
= never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? any.array : never : never)
type nonfiniteOf<xs, invariant extends any.array>
= 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<xs extends any.array> = never | head<xs>
/** {@link head `array.head`} returns just the _first_ element of an array */
type head<xs extends any.array>
= [xs] extends [nonempty.array<infer head, any>] ? 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<xss extends any.array<any.array>> = never | { [ix in keyof xss]: xss[ix][0] }
/** {@link snd `array.snd`} returns just the _second_ element of an array */
type snd<xs extends any.array> = never | head<tail<xs>>
/** {@link snds `array.snds`} returns just the _second_ item of _every_ element of a matrix (an array of arrays) */
type snds<xss extends any.array<any.array>> = 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.array> = 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<xss extends any.array<any.array>> = never | { [ix in keyof xss]: tail<xss[ix]> }

/** {@link last `array.last`} returns _just_ every element _but_ the _last_ element of an array */
type last<xs extends any.array> = 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 any.array> = xs extends [...infer lead, any] ? lead : never
}

export declare namespace nonemptyArray {
Expand All @@ -65,26 +95,3 @@ export declare namespace nonemptyArray {
: never
: never
}

type finite<xs> = check.is.tuple<xs, any.array, "hush">
type finiteOf<xs, invariant extends any.array> = check.is.tuple<xs, invariant, "hush">
type nonfinite<xs>
= never | ([xs] extends [any.array] ? [number] extends [xs["length"]] ? any.array : never : never)
type nonfiniteOf<xs, invariant extends any.array>
= 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<xs extends any.array> = never | head<xs>

type head<xs extends any.array>
= [xs] extends [nonempty.array<infer head, any>] ? head : (undefined | xs[number])

type heads<xss extends any.array<any.array>> = never | { [ix in keyof xss]: xss[ix][0] }

type snd<xs extends any.array> = never | head<tail<xs>>
type snds<xss extends any.array<any.array>> = never | { [ix in keyof xss]: xss[ix][1] }

type tail<xs extends any.array> = xs extends [any, ...infer tail] ? tail : never
type tails<xss extends any.array<any.array>> = never | { [ix in keyof xss]: tail<xss[ix]> }