Dan Burkert has posted comments on this change.
Change subject: util: add Status::AndThen combinator
......................................................................
Patch Set 3:
Here's an example from a patch which builds off this, in
CatalogManager::CreateTable
// a. Validate the user request.
Schema client_schema;
s = SchemaFromPB(req.schema(), &client_schema)
.AndThen([&] () {
return
ValidateIdentifier(req.database_name()).CloneAndPrepend("invalid database
name");
}).AndThen([&] () {
return ValidateIdentifier(req.table_name()).CloneAndPrepend("invalid
table name");
}).AndThen([&] () {
return ValidateClientSchema(client_schema);
}).AndThen([&] () {
if (client_schema.has_column_ids()) {
return Status::InvalidArgument("user requests should not have
Column IDs");
} else {
return Status::OK();
}
});
if (!s.ok()) {
return SetError(MasterErrorPB::INVALID_SCHEMA, s);
}
For what it's worth, this is a common method to have on status-like types in
functional languages, for instance Scala's Try.flatMap[1] or Rust's
Result.and_then [2].
[1]:
http://www.scala-lang.org/api/2.12.x/scala/util/Try.html#flatMap[U](f:T=>scala.util.Try[U]):scala.util.Try[U]
[2]: https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then
--
To view, visit http://gerrit.cloudera.org:8080/7399
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia6e1a79ff95406825d4238a8157d242252562805
Gerrit-PatchSet: 3
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-Owner: Dan Burkert <[email protected]>
Gerrit-Reviewer: Alexey Serbin <[email protected]>
Gerrit-Reviewer: Dan Burkert <[email protected]>
Gerrit-Reviewer: Kudu Jenkins
Gerrit-Reviewer: Tidy Bot
Gerrit-Reviewer: Todd Lipcon <[email protected]>
Gerrit-HasComments: No