Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-partial-or-complete
keep going with a partial value or stop with the result
https://github.com/lue-bird/elm-partial-or-complete
elm fold loop recursion stoppable
Last synced: 25 days ago
JSON representation
keep going with a partial value or stop with the result
- Host: GitHub
- URL: https://github.com/lue-bird/elm-partial-or-complete
- Owner: lue-bird
- License: mit
- Created: 2023-04-29T14:32:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-06-29T16:03:52.000Z (over 1 year ago)
- Last Synced: 2024-12-09T18:02:07.113Z (about 1 month ago)
- Topics: elm, fold, loop, recursion, stoppable
- Language: Elm
- Homepage: https://dark.elm.dmy.fr/packages/lue-bird/elm-partial-or-complete/latest/
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# [`PartialOrComplete`](PartialOrComplete)
```elm
| Partial partial -- keep going
| Complete complete -- done
```– a _pattern_ used in
- ```elm
type Step folded
= Continue folded
| Done folded
stoppableFold :
folded
-> (element -> folded -> Step folded)
-> Structure element
-> folded
```
- [`List.Extra.stoppableFold`](https://dark.elm.dmy.fr/packages/elm-community/list-extra/latest/List-Extra#stoppableFold)
- [`FastDict.stoppableFold`](https://dark.elm.dmy.fr/packages/miniBill/elm-fast-dict/1.1.0/FastDict#stoppableFold)
- ```elm
type Step state complete
= Loop state
| Done complete
loop :
state
-> (state -> Magic (Step state complete))
-> Magic complete
```
- [`Parser.loop`](https://dark.elm.dmy.fr/packages/elm/parser/latest/Parser#loop)
- [`Bytes.Decode.loop`](https://dark.elm.dmy.fr/packages/elm/bytes/1.0.8/Bytes-Decode#loop)
- [`Bytes.Parser.loop`](https://dark.elm.dmy.fr/packages/zwilias/elm-bytes-parser/1.0.0/Bytes-Parser#loop)
- [`Parser.Recoverable.loop`](https://dark.elm.dmy.fr/packages/the-sett/parser-recoverable/1.0.0/Parser-Recoverable#loop),
- [`State.tailRec(M)`](https://dark.elm.dmy.fr/packages/folkertdev/elm-state/latest/State#tailRec)
- ```elm
type Step
= InProgress InProgress
| Done Complete
step : InProgress -> Step
```
step-by-step testing, benchmarking, parsing, simplifying/shrinking, evaluating, ...
- [`Trampoline.StepResult`](https://dark.elm.dmy.fr/packages/mgree/trampoline/latest/Trampoline#StepResult)Maybe it makes sense to have a shared type in a shared place?
With shared documentation and helpers?## where [`PartialOrComplete`](PartialOrComplete) is already being used
Step through a structure; stop when you're done.
- [`List.Linear.foldUntilCompleteFrom`](https://dark.elm.dmy.fr/packages/lue-bird/elm-linear-direction/latest/List-Linear#foldUntilCompleteFrom)
- [`KeysSet.foldUntilCompleteFrom`](https://dark.elm.dmy.fr/packages/lue-bird/elm-keysset/latest/KeysSet#foldUntilCompleteFrom)Suggestions & additions welcome!
## reasons for avoiding it
- You don't want to require users to manually install this package
for just the stoppable type and helpers?
- In your domain, variant names can be more specific and descriptive
than "partial" and "complete"?- You like avoiding package dependencies?
→ You can expect this package to not have breaking changes- You have the same intermediate and complete types and use
```elm
type InProgress
= Atom { info : Info, report : Maybe Report }
| Structured (List InProgress)
step : InProgress -> InProgress
isDone : InProgress -> Bool
```
→ I do suggest looking into
```elm
type Thing report
= Atom { info : Info, report : report }
| Structured (List (Thing report))
step : Thing (Maybe Report) -> PartialOrComplete (Thing (Maybe Report)) (Thing Report)
```
I'd say that's a tiny tiny bit nicer because you can't miss that you're already done.