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

feat: add Record.findFirstEntry #4500

Open
wants to merge 6 commits into
base: next-minor
Choose a base branch
from

Conversation

vinassefranche
Copy link
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Adds Record.FindFirstEntry

import { Record, Option } from "effect"

const record = { a: 1, b: 2, c: 3 }
const result = Record.findFirstEntry(record, (value, key) => value > 1 && key !== "b")
assert.deepStrictEqual(result, Option.some(["c", 3]))

I could also add Record.FindFirst and Record.FindFirstKey if this gets accepted as it would a simple Option.map on findFirstEntry

Related

  • Related Issue #
  • Closes #

Copy link

changeset-bot bot commented Feb 24, 2025

🦋 Changeset detected

Latest commit: 7b9d284

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
effect Minor
@effect/cli Major
@effect/cluster-browser Major
@effect/cluster-node Major
@effect/cluster-workflow Major
@effect/cluster Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major
@effect/ai Major
@effect/ai-anthropic Major
@effect/ai-openai Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

.type.toBe<Option.Option<[string, string | number]>>()
expect(pipe(string$numbersOrStrings, Record.findFirstEntry((a, _) => predicateNumbersOrStrings(a))))
.type.toBe<Option.Option<[string, string | number]>>()
expect(Record.findFirstEntry(string$numbersOrStrings, (a, _) => Predicate.isString(a)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expect fails with Typescript 5.4.5. If you have any tip on how to fix it, I'm all ears!

@effect-bot effect-bot force-pushed the next-minor branch 19 times, most recently from 495b3b2 to 5d68000 Compare February 27, 2025 17:29
@effect-bot effect-bot force-pushed the next-minor branch 2 times, most recently from fa33360 to 044cb83 Compare February 27, 2025 22:36
@effect-bot effect-bot force-pushed the next-minor branch 2 times, most recently from e21867a to 629c0cf Compare February 28, 2025 09:38
@effect-bot effect-bot force-pushed the next-minor branch 7 times, most recently from e2610c7 to 0f2ebba Compare March 3, 2025 03:56
@vinassefranche vinassefranche force-pushed the add-record-find-first branch from be08a08 to d77362c Compare March 3, 2025 09:35
@vinassefranche vinassefranche force-pushed the add-record-find-first branch from d77362c to 7b9d284 Compare March 3, 2025 17:59
@effect-bot effect-bot force-pushed the next-minor branch 4 times, most recently from e3284ed to d8b4da5 Compare March 3, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Discussion Ongoing
Development

Successfully merging this pull request may close these issues.

2 participants