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

Release queue: minor #3410

Merged
merged 12 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix Array.replaceOption signature (#3497)
  • Loading branch information
gcanti authored and tim-smart committed Aug 30, 2024
commit bc3a1731190bf35fab2c28c973ffbeb569cc71c9
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