From 5514d05b5cd586ff5868b8bd41c959e95e6c33cd Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Fri, 17 Jan 2025 18:19:52 +0100 Subject: [PATCH] Array: Fix `Either` import and correct `partition` example. (#4287) --- .changeset/stupid-crabs-return.md | 5 ++++ packages/effect/src/Array.ts | 40 ++++++++++++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 .changeset/stupid-crabs-return.md diff --git a/.changeset/stupid-crabs-return.md b/.changeset/stupid-crabs-return.md new file mode 100644 index 00000000000..a5566a6d6c3 --- /dev/null +++ b/.changeset/stupid-crabs-return.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Array: Fix `Either` import and correct `partition` example. diff --git a/packages/effect/src/Array.ts b/packages/effect/src/Array.ts index 2802a3aff55..6c8f197cc86 100644 --- a/packages/effect/src/Array.ts +++ b/packages/effect/src/Array.ts @@ -4,7 +4,7 @@ * @since 2.0.0 */ -import type { Either as array_ } from "./Either.js" +import type { Either } from "./Either.js" import * as E from "./Either.js" import * as Equal from "./Equal.js" import * as Equivalence from "./Equivalence.js" @@ -2457,11 +2457,11 @@ export const filterMapWhile: { * @since 2.0.0 */ export const partitionMap: { - (f: (a: A, i: number) => array_): (self: Iterable) => [left: Array, right: Array] - (self: Iterable, f: (a: A, i: number) => array_): [left: Array, right: Array] + (f: (a: A, i: number) => Either): (self: Iterable) => [left: Array, right: Array] + (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] } = dual( 2, - (self: Iterable, f: (a: A, i: number) => array_): [left: Array, right: Array] => { + (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] => { const left: Array = [] const right: Array = [] const as = fromIterable(self) @@ -2514,7 +2514,7 @@ export const getSomes: >, X = any>( * @category filtering * @since 2.0.0 */ -export const getLefts = >>(self: T): Array>> => { +export const getLefts = >>(self: T): Array>> => { const out: Array = [] for (const a of self) { if (E.isLeft(a)) { @@ -2541,9 +2541,9 @@ export const getLefts = >>(self: T): Array>>( +export const getRights = >>( self: T -): Array>> => { +): Array>> => { const out: Array = [] for (const a of self) { if (E.isRight(a)) { @@ -2580,6 +2580,17 @@ export const filter: { /** * Separate elements based on a predicate that also exposes the index of the element. * + * @example + * ```ts + * import { Array } from "effect" + * + * const numbers = [1, 2, 3, 4] + * + * const result = Array.partition(numbers, n => n % 2 === 0) + * + * assert.deepStrictEqual(result, [[1, 3], [2, 4]]) + * ``` + * * @category filtering * @since 2.0.0 */ @@ -2615,21 +2626,12 @@ export const partition: { /** * Separates an `Iterable` into two arrays based on a predicate. * - * @example - * ```ts - * import { Array } from "effect" - * - * const numbers = [1, 2, 3, 4] - * const result = Array.partition(numbers, n => n % 2 === 0) - * assert.deepStrictEqual(result, [[1, 3], [2, 4]]) - * ``` - * * @category filtering * @since 2.0.0 */ -export const separate: >>( +export const separate: >>( self: T -) => [Array>>, Array>>] = partitionMap( +) => [Array>>, Array>>] = partitionMap( identity ) @@ -2785,7 +2787,7 @@ export const flatMapNullable: { * @since 2.0.0 */ export const liftEither = , E, B>( - f: (...a: A) => array_ + f: (...a: A) => Either ) => (...a: A): Array => { const e = f(...a)