purescript-lists icon indicating copy to clipboard operation
purescript-lists copied to clipboard

Lazy List's mapWithIndex is not lazy

Open worldmaker18349276 opened this issue 1 year ago • 0 comments

https://github.com/purescript/purescript-lists/blob/b113451e5b41cad87d669a3165f955c71cd863e2/src/Data/List/Lazy/Types.purs#L116

The implementation of FunctorWithIndex for Lazy List uses folding, which, unlike Functor, is not lazy.

It should be:

instance functorWithIndexList :: FunctorWithIndex Int List where
  mapWithIndex f xs = List (go 0 <$> unwrap xs)
    where
    go i = \step -> case step of
      Nil -> Nil
      Cons x xs' -> Cons (f i x) (List (go (i + 1) <$> unwrap xs'))

worldmaker18349276 avatar Aug 02 '24 15:08 worldmaker18349276