Lazy List's mapWithIndex is not lazy

Open
#218 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Domain
backend

Research direction

Start in src/Data/List/Lazy/Types.purs at the linked FunctorWithIndex instance around line 116. Compare its folding implementation with the lazy Functor implementation, then check how the proposed recursive mapping handles the list one step at a time. Done means mapWithIndex preserves laziness while supplying each element’s index; the issue provides no test file to run.

Written by the indexing model from the issue text.

Description

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'))
Dominant language
PureScript
Stars
61
Forks
50
Avg merge
2d 6h
Merged PRs (30d)
1

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from purescript/purescript-lists

All issues in purescript/purescript-lists

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.