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

A.takeWhile acting like A.filter #60

Closed
ssnielsen opened this issue Dec 9, 2022 · 3 comments
Closed

A.takeWhile acting like A.filter #60

ssnielsen opened this issue Dec 9, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ssnielsen
Copy link

ssnielsen commented Dec 9, 2022

First of all, thanks for a solid library - it's really a breeze to use!

While doing a bit of Advent of Code, I noticed unexpected output from A.takeWhile - essentially it seems to act more like A.filter

Examples:

// ts-belt:
A.takeWhile([3, 5, 3], n => n < 4); 
// Returns [3, 3]

I'd expect to get back the single-element list: [3].

Ramda (and other similar libraries):

// ramda:
R.takeWhile(n => n < 4, [3, 5, 3])
// Returns [3]

Smells a bit like a bug to me 😉

Also - looking at a bit further, it looks like this case isn't covered by the tests

Btw, the version in question is 3.13.1

@mobily mobily added the bug Something isn't working label Dec 9, 2022
@mobily mobily self-assigned this Dec 9, 2022
@ssnielsen
Copy link
Author

ssnielsen commented Dec 10, 2022

Btw, if you're ok with it, I'm definitely willing to give it a go at fixing it 😉 (forgot to say that above)

@mobily
Copy link
Owner

mobily commented Dec 10, 2022

@ssnielsen thanks for spotting this issue! indeed, takeWhile was implemented incorrectly, I fixed it up in v4.0.0-rc.2 :)

test case: 235f223#diff-39838e57d36e74e0f3b610bc317412d00c08c0f67a99d5b8f1cae4784ae33cfbR9

benchmarks:
CleanShot 2022-12-10 at 12 59 17@2x

@mobily mobily closed this as completed Dec 11, 2022
@lightwave
Copy link

Any chance this fix might be back-ported to v3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants