Add Fold1 pattern synonym & utilities #212
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change extends the API of
Control.Foldl.NonEmpty
by some of the exports suggested in #209:Fold1_
pattern synonympurely
purely_
premap
handles
foldOver
folded1
I created a naive benchmark that compares the execution time of
NonEmpty.map succ
Fold
FoldM
data Fold1 a b = forall x. Fold1 !(a -> x) !(x -> a -> x) !(x -> b)
imported qualified as
Foldl1
data Fold1 a b = Fold1 (a -> Fold a b)
from Fold1 data type definition & adding more folds/utilities to Control.Foldl.NonEmpty #209imported qualified as
L1
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 ofFold1
.The alternative definition of
Fold1
performs similar to theFold(M)
variants.Finally, the
Fold*
variants all perform worse thanNonEmpty.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 believeThus, I left the current definition unchanged and added the alternative definition as a pattern synonym.