boostorg / boostorg/system

Unwrapping fold and rewrapping as result

Open
#143 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
45
Forks
96
PR merge metrics
No merged PRs in 30d

Description

A common operation with "monadic" wrappers is to take a collection of wrapped values and repackage it as a wrapped collection of values. In other words `vector>` -> `result>`. In C++ this exact operation is too opinionated (we don't usually actually want to create a new container), so instead I propose a special "fold". Or actually several versions of it.

All three would have the signiture `R (Rng, Z, F)`.

The first version would require `Rng` to be a range of `result` and `F` have the signiture `auto (Z&, T&&) -> Z`. `R` would be `result`.

The second version would require `Rng` to be a range of `T`, and `F` have the signiture `auto (Z&, T&&) -> result`. `R` would be `result`.

The third version would require `Rng` to be a range of `result`, and `F` have the signiture `auto (Z&, T&&) -> result`. `R` would be `result`. The second version can be viewed as a degenerated version of the third version.

Below is an example of me my implementation of version 1 to implement a custom conversion from to `boost::json::value` to a container type. Container conversion provided by Boost.JSON have a similar structure. Possibly, I would actually prefer version 2 here (my source range isn't a range of results).

https://godbolt.org/z/74MsK345d

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.