Jump to conversation
Unresolved conversations (11)
@zah zah May 21, 2018
All in all, looks pretty great. For the intended support in `handleErrors` I imagined one more possible feature. There is a planned support in Nim for `varargs` generic types where the `varargs` parameter is mapped to a tuple (it's a relatively simple feature). We can then possibly add the option to instantiate `Result` with multiple possible error types (one of the goals of `handleErrors` is to make it easy to switch between `enum` errors and richer error types that can hold values).
result.nim
arnetheduck
@zah zah May 21, 2018
perhaps `ok` and `err` can also take advantage of the `result` symbol to offer the short-cut form from Rust that you've grown to like: ``` nim template ok(value: typed) {.dirty.} = result.ok(value); return proc works: R = if foo: ok 42 else: err "dummy" ``` A bit too polluting perhaps as `ok` and `err` are pretty common terms, but it looks quite nice.
result.nim
arnetheduck
@zah zah May 21, 2018
I'm not sure about this. It makes more sense for `items` to be lifted to iterate over the contents of `T`.
Outdated
result.nim
zah arnetheduck
@zah zah May 21, 2018
Perhaps this API should be optimized to take advantage of the `result` symbol in the proc. ```nim proc foo: Result[int, ref Exception] = if errorDetected: return captureStack() # this can figure out all the details from the `result` var. ```
result.nim
arnetheduck zah
@zah zah May 21, 2018
It may be possible to automatically lift all supported operators through some clever application of the dot operators. Have to tinker a bit with this.
Outdated
result.nim
arnetheduck
@zah zah May 21, 2018
There are some filed issues in Nim when using generic converters. Once fixed, perhaps it will be possible to automatically lift the conversion here.
result.nim
arnetheduck
@zah zah May 21, 2018
I know this style hasn't gained many followers in the Nim community yet, but I usually recommend to use implicit generics: ``` nim template isErr*(self: Result): bool = not self.isOk ``` I think the shorter code is more visually pleasing and it's more resilient to re-factoring (You can make changes to the generic parameters without touching all the procs in the module).
Outdated
result.nim
arnetheduck
@zah zah May 21, 2018
Similar to `ok` (regarding the signature)
Outdated
result.nim
@zah zah May 21, 2018
Similar to `ok` (regarding the signature)
Outdated
result.nim
@zah zah May 21, 2018
Perhaps you are using `auto` on purpose though? Again, a more precise signature is ```nim proc ok*[T, E](self: var Result[T, E], v: T) ``` or ```nim proc ok*(self: var Result, v: self.T) ```
Outdated
result.nim
@zah zah May 21, 2018
In theory, a more precise signature that should work is the following: ``` nim proc ok*(R: typedesc[Result], v: R.T): R ```
Outdated
result.nim
arnetheduck zah
Resolved conversations (0)