Skip to content

Commit

Permalink
Array: simplify signatures (`ReadonlyArray<any> | Iterable<any> = Ite… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 23, 2024
1 parent e22427c commit 608b01f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-papayas-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Array: simplify signatures (`ReadonlyArray<any> | Iterable<any> = Iterable<any>`)
34 changes: 34 additions & 0 deletions packages/effect/dtslint/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare const nonEmptyStrings: Array.NonEmptyArray<string>
declare const readonlyNumbers: ReadonlyArray<number>
declare const numbers: Array<number>
declare const strings: Array<string>
declare const iterNumbers: Iterable<number>
declare const iterStrings: Iterable<string>
declare const numbersOrStrings: Array<number | string>

declare const pimitiveNumber: number
Expand Down Expand Up @@ -712,30 +714,62 @@ flattenNonEmptyArray.pipe(Effect.map(Array.flatten))
// prependAll
// -------------------------------------------------------------------------------------

// Array + Array

// $ExpectType (string | number)[]
Array.prependAll(strings, numbers)

// $ExpectType (string | number)[]
pipe(strings, Array.prependAll(numbers))

// NonEmptyArray + Array

// $ExpectType [string | number, ...(string | number)[]]
Array.prependAll(nonEmptyStrings, numbers)

// $ExpectType [string | number, ...(string | number)[]]
pipe(nonEmptyStrings, Array.prependAll(numbers))

// Array + NonEmptyArray

// $ExpectType [string | number, ...(string | number)[]]
Array.prependAll(strings, nonEmptyNumbers)

// $ExpectType [string | number, ...(string | number)[]]
pipe(strings, Array.prependAll(nonEmptyNumbers))

// NonEmptyArray + NonEmptyArray

// $ExpectType [string | number, ...(string | number)[]]
Array.prependAll(nonEmptyStrings, nonEmptyNumbers)

// $ExpectType [string | number, ...(string | number)[]]
pipe(nonEmptyStrings, Array.prependAll(nonEmptyNumbers))

// Iterable + Array

// $ExpectType (string | number)[]
Array.prependAll(iterStrings, numbers)

// $ExpectType (string | number)[]
pipe(iterStrings, Array.prependAll(numbers))

// Iterable + NonEmptyArray

// $ExpectType [string | number, ...(string | number)[]]
Array.prependAll(iterStrings, nonEmptyNumbers)

// $ExpectType [string | number, ...(string | number)[]]
pipe(iterStrings, Array.prependAll(nonEmptyNumbers))

// NonEmptyArray + Iterable

// $ExpectType [string | number, ...(string | number)[]]
Array.prependAll(nonEmptyStrings, iterNumbers)

// $ExpectType [string | number, ...(string | number)[]]
pipe(nonEmptyStrings, Array.prependAll(iterNumbers))

// -------------------------------------------------------------------------------------
// appendAll
// -------------------------------------------------------------------------------------
Expand Down
33 changes: 16 additions & 17 deletions packages/effect/src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export const prepend: {
* @since 2.0.0
*/
export const prependAll: {
<S extends ReadonlyArray<any> | Iterable<any>, T extends ReadonlyArray<any> | Iterable<any>>(
<S extends Iterable<any>, T extends Iterable<any>>(
that: T
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
Expand Down Expand Up @@ -363,7 +363,7 @@ export const append: {
* @since 2.0.0
*/
export const appendAll: {
<S extends ReadonlyArray<any> | Iterable<any>, T extends ReadonlyArray<any> | Iterable<any>>(
<S extends Iterable<any>, T extends Iterable<any>>(
that: T
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
Expand Down Expand Up @@ -1365,7 +1365,7 @@ export const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyA
export const intersperse: {
<B>(
middle: B
): <S extends ReadonlyArray<any> | Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>
): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>
<A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>
<A, B>(self: Iterable<A>, middle: B): Array<A | B>
} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {
Expand Down Expand Up @@ -1478,7 +1478,7 @@ export const setNonEmptyLast: {
* @since 2.0.0
*/
export const rotate: {
(n: number): <S extends ReadonlyArray<any> | Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
(n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>
<A>(self: Iterable<A>, n: number): Array<A>
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
Expand Down Expand Up @@ -1567,7 +1567,7 @@ export const contains: {
* @since 2.0.0
*/
export const chop: {
<S extends ReadonlyArray<any> | Iterable<any>, B>(
<S extends Iterable<any>, B>(
f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
<A, B>(
Expand Down Expand Up @@ -1742,7 +1742,7 @@ export const copy: {
export const chunksOf: {
(
n: number
): <S extends ReadonlyArray<any> | Iterable<any>>(
): <S extends Iterable<any>>(
self: S
) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>
Expand Down Expand Up @@ -1864,7 +1864,7 @@ export const groupBy: {
* @since 2.0.0
*/
export const unionWith: {
<S extends ReadonlyArray<any> | Iterable<any>, T extends ReadonlyArray<any> | Iterable<any>>(
<S extends Iterable<any>, T extends Iterable<any>>(
that: T,
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
Expand Down Expand Up @@ -1906,9 +1906,9 @@ export const unionWith: {
* @since 2.0.0
*/
export const union: {
<T extends ReadonlyArray<any> | Iterable<any>>(
<T extends Iterable<any>>(
that: T
): <S extends ReadonlyArray<any> | Iterable<any>>(
): <S extends Iterable<any>>(
self: S
) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
<A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>
Expand Down Expand Up @@ -2026,23 +2026,22 @@ export declare namespace ReadonlyArray {
/**
* @since 2.0.0
*/
export type Infer<S extends ReadonlyArray<any> | Iterable<any>> = S extends ReadonlyArray<infer A> ? A
export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A
: S extends Iterable<infer A> ? A
: never

/**
* @since 2.0.0
*/
export type With<S extends ReadonlyArray<any> | Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ?
NonEmptyArray<A>
export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>
: Array<A>

/**
* @since 2.0.0
*/
export type OrNonEmpty<
S extends ReadonlyArray<any> | Iterable<any>,
T extends ReadonlyArray<any> | Iterable<any>,
S extends Iterable<any>,
T extends Iterable<any>,
A
> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>
: T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>
Expand All @@ -2052,8 +2051,8 @@ export declare namespace ReadonlyArray {
* @since 2.0.0
*/
export type AndNonEmpty<
S extends ReadonlyArray<any> | Iterable<any>,
T extends ReadonlyArray<any> | Iterable<any>,
S extends Iterable<any>,
T extends Iterable<any>,
A
> = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>
: Array<A>
Expand Down Expand Up @@ -2700,7 +2699,7 @@ export const forEach: {
* @since 2.0.0
*/
export const dedupeWith: {
<S extends ReadonlyArray<any> | Iterable<any>>(
<S extends Iterable<any>>(
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<A>
Expand Down

0 comments on commit 608b01f

Please sign in to comment.