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

Add A.flatMap #64

Closed ivan-kleshnin closed 1 year ago

ivan-kleshnin commented 1 year ago

This crucial function is missing. I guess, accidentally because other namespaces expose it. For example: https://mobily.github.io/ts-belt/api/option#flatmap I've double checked it's not exposed under a different name like chain or concatMap.

mobily commented 1 year ago

@ivan-kleshnin added in v4.0.0-rc.5 🚀 https://github.com/mobily/ts-belt/commit/14a5c153b4d554cd304b0c6e44b671fc1d7d1d81

benchmarks:

flatMap (single function call)

✔  @mobily/ts-belt  27,383,074.99  ops/sec  ±0.33%  (99 runs)  fastest
██████████████████████████████████████████████████████████████████████

✔  remeda            1,759,670.66  ops/sec  ±1.36%  (97 runs)  -93.57%
████

✔  ramda             1,392,700.93  ops/sec  ±0.52%  (91 runs)  -94.91%
███

✔  rambda            4,870,498.47  ops/sec  ±0.92%  (98 runs)  -82.21%
████████████

✔  lodash/fp         5,749,906.26  ops/sec  ±0.78%  (87 runs)  -79.00%
██████████████

→ Fastest is @mobily/ts-belt

flatMap (function call inside pipe)

✔  @mobily/ts-belt  21,116,789.82  ops/sec  ±2.48%  (94 runs)  fastest
██████████████████████████████████████████████████████████████████████

✔  remeda            2,500,686.11  ops/sec  ±1.44%  (98 runs)  -88.16%
████████

✔  ramda               872,490.77  ops/sec  ±0.77%  (92 runs)  -95.87%
██

✔  rambda            4,248,478.35  ops/sec  ±0.54%  (93 runs)  -79.88%
██████████████

✔  lodash/fp           896,410.20  ops/sec  ±1.63%  (93 runs)  -95.75%
██

→ Fastest is @mobily/ts-belt