Gabriella439 / foldl

Composable, streaming, and efficient left folds
BSD 3-Clause "New" or "Revised" License
159 stars 51 forks source link

Add Fold1 pattern synonym & utilities #212

Closed Topsii closed 1 month ago

Topsii commented 1 month ago

This change extends the API of Control.Foldl.NonEmpty by some of the exports suggested in #209:

I created a naive benchmark that compares the execution time of

image Note that the y-axis uses a logarithmic scale.

In this benchmark the current definition of the Fold1 data type clearly performs worse than the alternative definition of Fold1. The alternative definition of Fold1 performs similar to the Fold(M) variants. Finally, the Fold* variants all perform worse than NonEmpty.map succ.

Personally, I favor changing the definition of the Fold1 data type and turning the current definition into a pattern synonym. However, in #209 you mentioned you believe

that for most functions the existing definition promotes the greatest code reuse.

Thus, I left the current definition unchanged and added the alternative definition as a pattern synonym.

Gabriella439 commented 1 month ago

Thank you for doing this!