Open matthewleon opened 6 years ago
This seems very similar to the implementation used in #132; can this be abstracted into a single function which all of these depend on? I also wouldn't want to have foldl
do it the fast way and the other two Foldable
member implementations do it the slow way, ideally.
This seems very similar to the implementation used in #132; can this be abstracted into a single function which all of these depend on?
Will try.
I also wouldn't want to have foldl do it the fast way and the other two Foldable member implementations do it the slow way, ideally.
foldMap
is switched to use foldl
. I'll try giving foldr
a similar rewrite. I'm not sure the benefits would be as drastic, as you won't get TCO.
I also wouldn't want to have foldl do it the fast way and the other two Foldable member implementations do it the slow way, ideally.
After attempting to do this, I've restored right folds to using the intermediate lists. Any attempt to do a right fold directly on the Map
is not stack-safe.
This seems very similar to the implementation used in #132; can this be abstracted into a single function which all of these depend on?
I can't see a way to do this. It seems to me that folding and toUnfoldable
are in some way "opposites". They bear a superficial similarity, but I can't see have them rely on a common function.
I've edited down my last two posts here... I believe common functionality between keys
, values
, and toAscUnfoldable
can indeed by refactored. I think that's out of scope for this particular PR though. I will try some strategies on the appropriate PR.
solves #134
This gives over a 10x speed improvement on larger maps (compare branch https://github.com/matthewleon/purescript-maps/tree/foldl-bench):
before
after