Closed
Description
E.g. this implementation does not crash and is more efficient, but it has an additional type class constraint. I'm not aware of the implications of this constraint
foldM :: forall m a b. MonadRec m => (a -> b -> m a) -> a -> Array b -> m a
foldM func init array = tailRecM2 go init 0
where
go res index | index >= length array = pure (Right res)
go res index = do
res' <- func res (unsafePartial (unsafeIndex array index))
pure $ Left {a:res', b:(index + 1)}
Metadata
Metadata
Assignees
Labels
No labels