You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at the current implementation of separate and looks like at least for the list-like Fs we could benefit from a single-pass implementation (well, not for lists since list's combine is ++, but for some structures which have more efficient combine implementations :)).
defseparateFoldable[G[_, _], A, B](fgab: F[G[A, B]])(implicitG:Bifoldable[G],
FF:Foldable[F]): (F[A], F[B]) = {
FF.foldLeft(fgab, (empty[A], empty[B])) { case (mamb, gab) =>G.bifoldLeft(gab, mamb)(
(t, a) => (combineK(t._1, pure(a)), t._2),
(t, b) => (t._1, combineK(t._2, pure(b)))
)
}
}
In any case, for foldables this would at least reduce the number of empty allocations etc etc.
Note: I'm obviously not suggesting replacing the current one which is strictly more generic, but adding an alternative (pun not intended) implementation alongside existing one.
The text was updated successfully, but these errors were encountered:
I was looking at the current implementation of
separate
and looks like at least for the list-likeF
s we could benefit from a single-pass implementation (well, not for lists since list's combine is++
, but for some structures which have more efficientcombine
implementations :)).Compare current implementation:
to the one proposed:
In any case, for foldables this would at least reduce the number of
empty
allocations etc etc.Note: I'm obviously not suggesting replacing the current one which is strictly more generic, but adding an alternative (pun not intended) implementation alongside existing one.
The text was updated successfully, but these errors were encountered: