mobily / ts-belt

🔧 Fast, modern, and practical utility library for FP in TypeScript.
https://mobily.github.io/ts-belt
MIT License
1.08k stars 30 forks source link

A.dropWhile is completely broken #101

Open ivan-kleshnin opened 6 months ago

ivan-kleshnin commented 6 months ago

A.dropWhile drops ALL items matching the predicate. It behaves exactly like A.reject:

import {A,D} from "@mobily/ts-belt"

console.log(
  A.dropWhile([0 ,           1, 0, 0, 0], (x) => x == 0),       // should drop the first zero
  A.reject   ([0 ,           1, 0, 0, 0], (x) => x == 0),       // should drop all zeros
  A.dropWhile([{},{foo: "Bar"},{},{},{}], (x) => D.isEmpty(x)), // should drop the first empty obj
  A.reject([{},{foo: "Bar"},{},{},{}], (x) => D.isEmpty(x)),    // should drop all empty objs
)
[ 1 ] // dropWhile, expected [ 1, 0, 0, 0 ]
[ 1 ] // reject
[ { foo: 'Bar' } ] // dropWhile, expected [ { foo: 'Bar' }, {}, {}, {} ]
[ { foo: 'Bar' } ] // reject
JUSTIVE commented 5 months ago

Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.