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
A specialized version of mapAccumWhile that keeps folding as long as the function argument returns 'Right'
foldWhile :: (Monad m) => (a -> s -> Either s s) -> s -> C.ConduitT a o m s
foldWhile f = loop
where
loop !s = C.await >>= maybe (pure s) go
where
go a = either (return $!) loop $ f a s
The text was updated successfully, but these errors were encountered:
I found a need for this while writing a family of stochastic gradient descent algorithms; the conduit processes one data point of type a at a time and stops accumulating state when a convergence or divergence criterion is met.
Seems reasonable to me. Only complaint I can think of: it hides away information about whether it was an end-of-stream versus a Left value produced by f. It may make more sense to generalize a bit to:
A specialized version of
mapAccumWhile
that keeps folding as long as the function argument returns 'Right'The text was updated successfully, but these errors were encountered: