Add more ergonomic ways to define folds and scans
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start by reading the fold and scan APIs, especially Fold.foldlM', and the inline example using MutArray in the issue. Work out how flipped fold and scan variants should accept a termination condition, then check the existing API tests for the expected behavior. Done means both folds and scans have ergonomic flipped forms with termination conditions.
Written by the indexing model from the issue text.
Description
Flipped versions of folds are better when we need to define the fold inline.
primes :: MonadIO m => Fold m Int (MutArray Int)
primes =
flip Fold.foldlM' (pure MutArray.empty)
$ \arr n -> do
isPrime <-
Stream.fold (Fold.all (\p -> n `mod` p /= 0))
$ Stream.takeWhile (\p -> p * p <= n)
$ MutArray.read arr
if isPrime
then MutArray.snoc arr n
else pure arr
We can call the flipped version as foldWith. We can also add a termination condition, which makes it more like a familiar for loop.
The applies to scans as well.
- Dominant language
- Haskell
- Stars
- 926
- Forks
- 71
- Avg merge
- 6h 49m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from composewell/streamly
-
takeInterval yields nothing, dropInterval drops nothingPossibly taken @GuillaumedeVolpiano claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
composewell/streamly#3271 ·
-
Parser: many accepts input that ends inside an elementPossibly taken @GuillaumedeVolpiano claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
composewell/streamly#3270 ·
-
aspect:api
Difficulty 4/5 1-2 days Newbie friendliness 48/100
composewell/streamly#3206 ·
-
api:breaking aspect:api aspect:filesystem
Difficulty 4/5 1-2 days Newbie friendliness 35/100
composewell/streamly#3203 ·
-
type:performance
Difficulty 4/5 3-5 days Newbie friendliness 32/100
composewell/streamly#3200 · 2 comments ·
All issues in composewell/streamly
Similar issues
-
bug desktop
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
simplex-chat/simplex-chat#8291 ·
Maintainers usually reply within 1 day
-
[BUG]: C# programs with top-level statements fail to compilePossibly taken @AsyncNigam claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
compiler-explorer/compiler-explorer#9625 · 1 comment ·
Maintainers usually reply within 1 day
-
needs triage type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
reflex-0.10Open
Difficulty 1/5 Under an hour Newbie friendliness 62/100
commercialhaskell/stackage#8180 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenZeppelin/canton-contracts#140 ·
Maintainers usually reply within 1 day