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 don't know if we want this, but note that you can define ifoldl' using Text.foldr or Text.foldl. Or if you have it for lists, you can compose it with Text.unpack.
ifoldlText :: (Int -> r -> Char -> r) -> r -> Text -> r
ifoldlText f r t = Text.foldr (\c k i x -> k (i+1) (f i x c)) (\_ x -> x) t 0 r
Test example
main :: IO ()
main = do
let f i x c = x ++ [(i, c)]
print (ifoldlText f [] "hello")
-- Output: [(0,'h'),(1,'e'),(2,'l'),(3,'l'),(4,'o')]
ifoldl':: (Int->b->Char->b) ->b->Text->b
ifoldl' f z0 =
go . stream
where
go (Stream next s0 _len) =
loop 0 z0 s0
where
loop !ix !z !s =case next s ofDone-> z
Skip s' -> loop ix z s'
Yield x s' -> loop (ix +1) (f ix z x) s'
Activity
Lysxia commentedon Feb 4, 2023
I don't know if we want this, but note that you can define
ifoldl'usingText.foldrorText.foldl. Or if you have it for lists, you can compose it withText.unpack.Test example
HuwCampbell commentedon Feb 5, 2023
Thanks. I ended up rolling this:
I'm not sure if it actually fuses any better.