diff --git a/packages/effect/src/Record.ts b/packages/effect/src/Record.ts
index 79d1912105d..76bb59cff8b 100644
--- a/packages/effect/src/Record.ts
+++ b/packages/effect/src/Record.ts
@@ -150,12 +150,14 @@ export const fromIterableWith: {
* ```ts
* import * as assert from "node:assert"
* import { fromIterableBy } from "effect/Record"
+ * import { pipe } from "effect/Function"
*
* const users = [
* { id: "2", name: "name2" },
* { id: "1", name: "name1" }
* ]
*
+ * // data-first
* assert.deepStrictEqual(
* fromIterableBy(users, user => user.id),
* {
@@ -163,15 +165,35 @@ export const fromIterableWith: {
* "1": { id: "1", name: "name1" }
* }
* )
+ *
+ * // data-last (pipeable)
+ * assert.deepStrictEqual(
+ * pipe(users, fromIterableBy(user => user.id)),
+ * {
+ * "2": { id: "2", name: "name2" },
+ * "1": { id: "1", name: "name1" }
+ * }
+ * )
* ```
*
* @category constructors
* @since 2.0.0
*/
-export const fromIterableBy = (
- items: Iterable,
- f: (a: A) => K
-): Record, A> => fromIterableWith(items, (a) => [f(a), a])
+export const fromIterableBy: {
+ (
+ f: (a: A) => K
+ ): (self: Iterable) => Record, A>
+ (
+ self: Iterable,
+ f: (a: A) => K
+ ): Record, A>
+} = dual(
+ 2,
+ (
+ self: Iterable,
+ f: (a: A) => K
+ ): Record, A> => fromIterableWith(self, (a) => [f(a), a])
+)
/**
* Builds a record from an iterable of key-value pairs.