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

Range/ClosedRange input support for NonEmpty initializer #55

Open
acosmicflamingo opened this issue Feb 10, 2023 · 0 comments
Open

Range/ClosedRange input support for NonEmpty initializer #55

acosmicflamingo opened this issue Feb 10, 2023 · 0 comments

Comments

@acosmicflamingo
Copy link

acosmicflamingo commented Feb 10, 2023

It looks like if I were to pass a NonEmptyArray an input of type Range or ClosedRange, NonEmptyArray actually produces an array comprising a single element, which is that range itself, instead of an array comprising the numbers within the range:

// Succeeds
func testArrayRange() {
  let input = 0...2
  let fooList: [String] = Array(input).map {
    "\($0)"
  }
  XCTAssertEqual(fooList, ["0", "1", "2"])
}

// Fails
func testNonEmptyArrayRange() {
  let input = 0...2
  let fooList: [String] = NonEmptyArray(input).map {
    "\($0)"
  }
  XCTAssertEqual(fooList, ["0", "1", "2"])
}

I tried creating a fix myself so I could just create a PR and save you all time, but I'm struggling to get a way to generate the expanded array and map that to an existing NonEmpty convenience initializer. Maybe I'm the only one in the world to try and use NonEmptyArray in this manner and it's not worth the effort ;)

@acosmicflamingo acosmicflamingo changed the title Range/ClosedRange as input to NonEmpty initializer Range/ClosedRange input support for NonEmpty initializer Feb 10, 2023
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