status-im / nim-stew

stew is collection of utilities, std library extensions and budding libraries that are frequently used at Status, but are too small to deserve their own git repository.
133 stars 18 forks source link

results: Add `isOkOr`, `isErrOr` #176

Closed arnetheduck closed 1 year ago

arnetheduck commented 1 year ago

These two helpers complete valueOr and errorOr to cover void cases where no value should be returned or Result[void, E] / Result[T, void] is being used - they can be used for a convient early-return style in side-effectful proc:s:

v.update().isOkOr:
  echo "update failed: ", error
kdeme commented 1 year ago

Great, I've hit that use case several times already :)