From fa2dcddd4741e0100edf131b4982a91874123444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodhnait=20=C3=89ta=C3=ADn?= Date: Sat, 22 May 2021 22:33:01 +0100 Subject: [PATCH] Rename CallWithContinuation trait to Then New name is shorter and better reflects the intent of the trait. --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 => {},