Skip to content

Commit

Permalink
fix Array.replaceOption signature (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and tim-smart committed Aug 23, 2024
1 parent 73dc641 commit ab7469d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
44 changes: 39 additions & 5 deletions packages/effect/dtslint/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1342,17 +1342,51 @@ Array.getSomes(hole<Iterable<Option.Option<number>> | Iterable<Option.Option<str
// $ExpectType string[]
Array.replace([], 0, "a")

// $ExpectType ("a" | 1 | 2)[]
Array.replace(new Set([1, 2] as const), 0, "a" as const)
// $ExpectType (string | number)[]
Array.replace(numbers, 0, "a")

// $ExpectType [number | "a", ...(number | "a")[]]
Array.replace(Array.of(1), 0, "a" as const)
Array.replace(nonEmptyNumbers, 0, "a" as const)

// $ExpectType ("a" | 1 | 2)[]
Array.replace(new Set([1, 2] as const), 0, "a" as const)

// $ExpectType string[]
pipe([], Array.replace(0, "a"))

// $ExpectType (string | number)[]
pipe(numbers, Array.replace(0, "a"))

// $ExpectType [number | "a", ...(number | "a")[]]
pipe(nonEmptyNumbers, Array.replace(0, "a" as const))

// $ExpectType ("a" | 1 | 2)[]
pipe(new Set([1, 2] as const), Array.replace(0, "a" as const))

// $ExpectType [number | "a", ...(number | "a")[]]
pipe(Array.of(1), Array.replace(0, "a" as const))
// -------------------------------------------------------------------------------------
// replaceOption
// -------------------------------------------------------------------------------------

// $ExpectType Option<string[]>
Array.replaceOption([], 0, "a")

// $ExpectType Option<(string | number)[]>
Array.replaceOption(numbers, 0, "a")

// $ExpectType Option<[number | "a", ...(number | "a")[]]>
Array.replaceOption(nonEmptyNumbers, 0, "a" as const)

// $ExpectType Option<("a" | 1 | 2)[]>
Array.replaceOption(new Set([1, 2] as const), 0, "a" as const)

// $ExpectType Option<string[]>
pipe([], Array.replaceOption(0, "a"))

// $ExpectType Option<(string | number)[]>
pipe(numbers, Array.replaceOption(0, "a"))

// $ExpectType Option<[number | "a", ...(number | "a")[]]>
pipe(nonEmptyNumbers, Array.replaceOption(0, "a" as const))

// $ExpectType Option<("a" | 1 | 2)[]>
pipe(new Set([1, 2] as const), Array.replaceOption(0, "a" as const))
6 changes: 2 additions & 4 deletions packages/effect/src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ export const insertAt: {
* import { Array } from "effect"
*
* const letters = ['a', 'b', 'c', 'd']
* const result = Array.replace(1, 'z')(letters)
* const result = Array.replace(letters, 1, 'z')
* assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])
*
* @since 2.0.0
Expand Down Expand Up @@ -1084,9 +1084,7 @@ export const replaceOption: {
<B>(
i: number,
b: B
): <A, S extends Iterable<A> = Iterable<A>>(
self: Iterable<A>
) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>
): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>
<A, B, S extends Iterable<A> = Iterable<A>>(
self: S,
i: number,
Expand Down

0 comments on commit ab7469d

Please sign in to comment.