diff --git a/src/main.rs b/src/main.rs index c5f0b47..34e9ba7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,11 +110,23 @@ fn main() { } } -trait WithContinuation { +// Represents a type characterised by a parameter T (either the type itself, or +// a type inside it, as in case of Option), 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 { fn then(&self, f: F) where F: FnOnce(&T); } -impl WithContinuation for std::option::Option { +impl Then for std::option::Option { fn then(&self, f: F) where F: FnOnce(&T) { match self { None => {},