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

add index argument to many functions in ReadonlyArray #1850

Merged
merged 3 commits into from
Jan 7, 2024

Conversation

matheuspuel
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Jan 2, 2024

🦋 Changeset detected

Latest commit: cb09879

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

This PR includes changesets to release 17 packages
Name Type
effect Patch
@effect/cli Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node Patch
@effect/platform Patch
@effect/printer-ansi Patch
@effect/printer Patch
@effect/rpc-http-node Patch
@effect/rpc-http Patch
@effect/rpc-nextjs Patch
@effect/rpc-workers Patch
@effect/rpc Patch
@effect/schema Patch
@effect/typeclass Patch

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

Copy link
Contributor

@gcanti gcanti left a comment

Choose a reason for hiding this comment

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

@matheuspuel I would add some dtslint tests, based on my experiments these tests fail:

// file: /packages/effect/dtslint/ReadonlyArray.ts

// -------------------------------------------------------------------------------------
// takeWhile
// -------------------------------------------------------------------------------------

ReadonlyArray.takeWhile(numbersOrStrings, (
  _item // $ExpectType string | number
) => true)

// fails: Parameter '_item' implicitly has an 'any' type.ts(7006)
ReadonlyArray.takeWhile(numbersOrStrings, (
  _item, // $ExpectType string | number
  _i // $ExpectType number
) => true)

pipe(
  numbersOrStrings,
  ReadonlyArray.takeWhile((
    _item // $ExpectType string | number
  ) => true)
)

// fails: Parameter '_item' implicitly has an 'any' type.ts(7006)
pipe(
  numbersOrStrings,
  ReadonlyArray.takeWhile((
    _item, // $ExpectType string | number
    _i // $ExpectType number
  ) => true)
)

unless you add a i: number parameter to refinements too:

export const takeWhile: {
  <A, B extends A>(refinement: (a: A, i: number) => a is B): (self: Iterable<A>) => Array<B>
  <B extends A, A = B>(predicate: (a: A, i: number) => boolean): (self: Iterable<B>) => Array<B>
  <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>
  <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {
  let i = 0
  const out: Array<A> = []
  for (const a of self) {
    if (!predicate(a, i)) {
      break
    }
    out.push(a)
    i++
  }
  return out
})

@gcanti gcanti merged commit d5a1949 into Effect-TS:main Jan 7, 2024
9 checks passed
@github-actions github-actions bot mentioned this pull request Jan 7, 2024
@matheuspuel matheuspuel deleted the index-arg-array branch January 10, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants