lune-climate / ts-results-es

A TypeScript implementation of Rust's Result and Option.
MIT License
98 stars 8 forks source link

Correct signature for Result.partition #172

Closed ConnorSinnott closed 2 months ago

ConnorSinnott commented 2 months ago

Hello @jstasiak! I must confess, I hadn't been able to update to the latest version of ts-results-es until recently. I had a shower thought last night that the signature for Result.partition was actually incorrect.

const all1 = Result.partition([ok0, ok1, err0, err1]);
expect(all1).toEqual([
    [ok0.value, ok1.value],
    [err0.error, err1.error],
]);
eq<typeof all1, [[number, boolean, never, never], [never, never, symbol, Error]]>(true);

The signature above implies that all is equal to [[number, boolean, undefined, undefined], [undefined, undefined, symbol, Error]] but this is not how that function works. Successes and errors will be pushed onto the partition array as they come, and we can't guarantee what index the successes or errors will be at. The real result from that function would be [[number, boolean], [symbol, Error]]

I've updated the signature and tests to reflect this. Could we patch this in? Very sorry for the inconvenience.

ConnorSinnott commented 2 months ago

Thank you @jstasiak! When can we expect this to be published? The 4.2.0 version has a bugged signature so to limit impact I think we'd want to patch this at your earliest convenience.