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

readonlyNonEmptyArray.union() should accept ReadonlyArray as second argument #1907

Open
licarth opened this issue Oct 9, 2023 · 0 comments

Comments

@licarth
Copy link

licarth commented Oct 9, 2023

🚀 Feature request

Current Behavior

readonlyNonEmptyArray.union() does not allow ReadonlyArray as second curried argument.

  pipe([1, 2], readonlyNonEmptyArray.union(N.Eq)([])) // does not compile

In my code, I had to do some workaround like this in order to keep the ReadonlyNonEmptyArray type when unioning a ReadonlyNonEmptyArray with a ReadonlyArray

  const doUnion = (nonEmptyArray: ReadonlyNonEmptyArray<number>, array: ReadonlyArray<number>) =>
    pipe(
      array,
      readonlyNonEmptyArray.fromReadonlyArray,
      option.match(
        () => nonEmptyArray,
        (array) => readonlyNonEmptyArray.union(N.Eq)(array)(nonEmptyArray)
      )
    )

EDIT 10.10 : Simpler workaround : use concat and then uniq

const doUnion = (
  nonEmptyArray: ReadonlyNonEmptyArray<number>,
  array: ReadonlyArray<number>,
) =>
  pipe(
    nonEmptyArray,
    readonlyNonEmptyArray.concat(N.Eq)(array),
    readonlyNonEmptyArray.uniq(N.Eq),
  );

Desired Behavior

  pipe([1, 2], readonlyNonEmptyArray.union(N.Eq)([])) // should work fine

and I could rewrite doUnion like this :

  const doUnion = (nonEmptyArray: ReadonlyNonEmptyArray<number>, array: ReadonlyArray<number>) =>
    pipe(nonEmptyArray, readonlyNonEmptyArray.union(N.Eq)(array))

Suggested Solution

Change signature of readonlyNonEmptyArray to accept ReadonlyArray as second.

Who does this impact? Who is this for?

People using readonlyNonEmptyArray

Describe alternatives you've considered

Additional context

Your environment

Software Version(s)
fp-ts 2.15
TypeScript 5.0.4
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

No branches or pull requests

1 participant