From 1e8ac329f8062ea6434fab517ae1d5e276ac1eff Mon Sep 17 00:00:00 2001 From: Tanguy Date: Mon, 20 Jun 2022 15:17:32 +0200 Subject: [PATCH] Simpler unpack for option --- questionable/binding.nim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/questionable/binding.nim b/questionable/binding.nim index 334e110..75458ee 100644 --- a/questionable/binding.nim +++ b/questionable/binding.nim @@ -1,16 +1,12 @@ import std/options import std/macros -proc placeholder(T: type): T = - discard - -template questionableUnpack*[T](expression: Option[T]): (T, bool) = +proc questionableUnpack[T](option: Option[T]): (T, bool) = ## Used internally - let option = expression - type T = typeof(option.unsafeGet()) - let res = if option.isSome: option.unsafeGet() else: placeholder(T) - (res, option.isSome) + if option.isSome: + return (option.unsafeGet(), true) + # return default macro `=?`*(name, expression): bool = ## The `=?` operator lets you bind the value inside an Option or Result to a