mobily / ts-belt

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

Make `A.partition` types aware of type guards #25

Closed bryanjswift closed 2 years ago

bryanjswift commented 2 years ago

It would be a lovely addition if partition were aware of type guard functions. Something like this

export function partition<A>(
  xs: ReadonlyArray<A>,
  predicate: (value: A) => boolean
): [A[], A[]];

export function partition<A, B extends A>(
  xs: ReadonlyArray<A>,
  predicate: (value: A) => value is B
): [B[], Exclude<A, B>[]];

I thought it might be sufficient to drop this in https://github.com/mobily/ts-belt/blob/master/src/Array/Array.ts but I'm not confident enough to open it as a PR without being able to test locally and the tooling for this project is new to me so I couldn't afford to invest the time in getting it set up yet.

mobily commented 2 years ago

It would be a lovely addition if partition were aware of type guard functions.

fully agree, I will look into it! 🚀

mobily commented 2 years ago

@bryanjswift fixed in v3.9.1 🚀