Skip to content

Commit

Permalink
fix: move never check to top
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Jul 8, 2023
1 parent e93baf5 commit 3ed4dce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-files-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"type-plus": patch
---

optimize `SplitAt` by moving never check of `DeleteCount` to top.
3 changes: 3 additions & 0 deletions type-plus/ts/array/array_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type { Integer } from '../numeric/integer.js'
import type { Negative } from '../numeric/negative.js'

/**
*
* 🦴 *utilities*
*
* Gets the normalized index to access the element of an array or tuple.
*
* ```ts
Expand Down
12 changes: 6 additions & 6 deletions type-plus/ts/array/array_plus.split_at.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export namespace SplitAt {
> = 0 extends A['length']
? IsTuple<Insert, [[...Insert, ...B], C], [B, C]>
: (Index extends B['length']
? _D<A, B, C, DeleteCount, Insert>
? NeverType<
DeleteCount,
[B, A],
_D<A, B, C, DeleteCount, Insert>>
: (A extends [infer Head, ...infer Tail]
? _<Tail, [...B, Head], [], Index, DeleteCount, Insert>
: 'unexpected: A does not extends [Head, ...Tail]'))
Expand All @@ -60,15 +63,12 @@ export namespace SplitAt {
C extends unknown[],
DeleteCount,
Insert extends unknown[],
> = NeverType<
DeleteCount,
[B, A],
DeleteCount extends C['length']
> = DeleteCount extends C['length']
? IsTuple<Insert, [[...B, ...Insert, ...A], C], [[...B, ...A], C]>
: (A extends [infer Head, ...infer Tail]
? _D<Tail, B, [...C, Head], DeleteCount, Insert>
: IsTuple<Insert, [[...Insert, ...B], C], [B, C]>
)
>

}

0 comments on commit 3ed4dce

Please sign in to comment.