Rename CallWithContinuation trait to Then

New name is shorter and better reflects the intent of the trait.
This commit is contained in:
Aodhnait Étaín 2021-05-22 22:33:01 +01:00
parent 3d26398ac7
commit fa2dcddd47

View file

@ -110,11 +110,23 @@ fn main() {
}
}
trait WithContinuation<T> {
// Represents a type characterised by a parameter T (either the type itself, or
// a type inside it, as in case of Option<T>), on which we can call a procedure
// that doesn't return anything.
//
// This is similar to `and_then` method that Option and Result expose, the only
// difference being in that this is only useful for procedures that perform
// side effects, as we don't return either the original value, or a new value
// being a result of the procedure.
//
// The function name this trait exposes is similar to `then` method found on
// bool type, as the original intent was to call it if the value is Some, and
// do nothing if it's None.
trait Then<T> {
fn then<F>(&self, f: F) where F: FnOnce(&T);
}
impl<T> WithContinuation<T> for std::option::Option<T> {
impl<T> Then<T> for std::option::Option<T> {
fn then<F>(&self, f: F) where F: FnOnce(&T) {
match self {
None => {},