Open treeowl opened 3 years ago
Note: if you really want to be super-lazy, we can at least avoid three entire Map
s and needing to worry about whether the resulting Map
s even contain selector thunks (or if they can leak space).
unzipWith f = unSBPair . traverseBia (SBPair . blah)
where
blah c = let
{-# NOINLINE fc #-} -- make sure the result of f c is shared
{-# NOINLINE a #-} -- make sure we get selector thunks
{-# NOINLINE b #-}
fc = f c
(a, b) = fc
in (a, b)
I've opened #164 with a version that preserves the precise laziness of the current version but without the leak potential and without building a third map structure.
(Personally, I like this version better than that one, but it's not my package.)
The previous
Map
(same forIntMap
throughout) instance would first map eagerly over thaMap
, producing an entireMap
full of thunks to apply theunzipWith
function. Then it would build two more entireMap
s full of thunks to select components of each pair. We can do it eagerly usingData.Biapplicative.traverseBia
and a simple pair bifunctor.