Add more ergonomic ways to define folds and scans

Aperta
#3,125 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
haskell
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Haskell
Stelle
926
Fork
71
Merge medio
6h 49m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di composewell/streamly

Tutte le issue di composewell/streamly

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.