commit | ce8a737c2fe2032561a9af915378fcc8b96fd926 | [log] [tgz] |
---|---|---|
author | RJ Ascani <rjascani@pigweed.infra.roller.google.com> | Wed Aug 10 21:41:52 2022 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Wed Aug 10 21:41:52 2022 +0000 |
tree | 7d6ece6fd91e85e3901182b61fbd84ea722a45bb | |
parent | 078a2ac65b46061cd4b2cca3b4ca3668cddf86b7 [diff] |
[roll pigweed] pw_result: Add and_then monadic operation This CL adds a monadic operation to pw::Result<T> for `and_then`. This method takes a function, which will be invoked only if the pw::Result<T> contains a value. If the pw::Result<T> contains a status, then that status will be returned. This is useful for chaining multiple operations that might fail. Result<std::string> GetIntegerString(); Result<int> ConvertStringToInteger(const std::string&); Result<int> x = GetIntegerString() .and_then(ConvertStringToInteger) .and_then([](int i) { return Result<int>(i * 2) }); Original-Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/100802 https://pigweed.googlesource.com/pigweed/pigweed pigweed Rolled-Commits: 6e3bc74cc4b71c0..940a29382017e8c Roller-URL: https://ci.chromium.org/b/8806182317674255089 Cq-Cl-Tag: roller-builder:pigweed-zephyr-roller Cq-Cl-Tag: roller-bid:8806182317674255089 CQ-Do-Not-Cancel-Tryjobs: true Change-Id: I8f97812b46068e6896a35aeecf358c19f4862309 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/zephyr-integration/+/105786 Bot-Commit: Pigweed Integration Roller <pigweed-integration-roller@pigweed.google.com.iam.gserviceaccount.com> Commit-Queue: Pigweed Integration Roller <pigweed-integration-roller@pigweed.google.com.iam.gserviceaccount.com>