28 Commits

Author SHA1 Message Date
jangko
faabd40c30
reduce compiler warnings 2023-02-14 21:35:54 +07:00
Jacek Sieka
447b23d3bf
results: work around field access bugs (#167)
* results: work around field access bugs

See:

* https://github.com/nim-lang/Nim/issues/3770
* https://github.com/nim-lang/Nim/issues/20900

* comment fixes

* add test

* document test better
2023-01-20 15:32:51 +01:00
Jacek Sieka
19a6aea53b
results: document experimental error shortcut, and its gotchas (#168) 2023-01-20 15:32:34 +01:00
Jacek Sieka
ac602b5086
results: print none for empty Opt instances (#164)
* results: print `none` for empty Opt instances

* fix test too
2023-01-16 09:01:31 +01:00
Jacek Sieka
8a1b6ab4dc
results: work around void member codegen issue (#150) 2022-11-11 14:26:59 +01:00
Tanguy
23da07c9b5
Fix compilation on devel (#146) 2022-10-29 21:48:51 +02:00
Jacek Sieka
142a408ca7
results: typo 2022-09-03 20:19:16 +02:00
Jacek Sieka
dad28a269f
result: add Opt.some / Opt.none (#117) 2022-06-17 13:45:22 +03:00
Jacek Sieka
b464505b4d
oops 2022-01-13 22:21:46 +01:00
Jacek Sieka
9d0f1167ca
results: [] for void (#103)
mostly for consistency.. but it's used in nim-eth tests
2022-01-13 22:02:44 +01:00
Jacek Sieka
6ad35b876f result: expose value/error in errorOr/valueOr
* fix error type as well
2022-01-11 16:39:12 +02:00
Jacek Sieka
d2ae2889e8
Result refresh (#96)
* `Result` refresh

* add full support for `Result[T, void]` (aka `Opt[T]` aka `Option[T]`)
* expand tests
* add `flatten`, `filter` of `Option` fame
* add `tryError` that raises a regular exception when result holds a
value
* fix `$` to print `ok`/`err` in lower-case, like the functions that
created the result
* add `orErr` that collapses all errors to a single value of a
potentially different type - useful when translating errors between
layers
* `capture` should work with `CatchableError`
* remove `Defect`-dependent tests

* Update stew/results.nim

* avoid redundant error message when converting error to string
* avoid multiple evaluation in `valueOr`
* add `unsafeError` to match `unsafeGet`
* let `valueOr` evaluate a block
* add `errorOr` to mirror `valueOr`
2022-01-10 00:22:09 +02:00
Zahary Karadjov
42475fd2f1
Fix a FieldError crash in the == comparison for Result[void, T] 2021-02-22 21:04:27 +02:00
Jacek Sieka
a0e8ec451e
results: include error when expecting (#76) 2021-02-10 11:05:29 +01:00
Mamy Ratsimbazafy
6d3e6a21ca
results.== with void, Reboot #73 addressing comments (#74) 2021-01-26 15:06:17 +01:00
Mamy Ratsimbazafy
b4b3841a85
Revert "Allow comparing Result[void, E] (#71)" (#73)
This reverts commit 068412ff4e01dcb03c73bc8b7e9805fe71c5f010.
2021-01-26 14:20:09 +01:00
Mamy Ratsimbazafy
068412ff4e
Allow comparing Result[void, E] (#71) 2021-01-26 14:12:08 +01:00
Jacek Sieka
e15c1ae012
results: prevent dangling cstring pointers in result (#63) 2020-12-09 17:21:12 +01:00
Zahary Karadjov
2b9e5f34d1
Some fixes for Result[T, void] 2020-09-29 21:31:20 +03:00
Jacek Sieka
ec2f52b0ce
results: make ? work with void (#50) 2020-07-13 18:09:45 +02:00
Mamy Ratsimbazafy
11aeb996ab
Error message typo 2020-06-23 19:46:18 +02:00
Giovanni Petrantoni
5fa6bb2742 Add a note about compiler crash with raises pragma (results) 2020-05-12 19:37:15 +09:00
Jacek Sieka
2d9226464d heterogenous or
Useful for translating `error` results
2020-05-08 18:54:36 +03:00
Jacek Sieka
8065e36c5a
results: fix non-void [] overload 2020-04-23 06:46:10 +02:00
Zahary Karadjov
4acc3866ed
Adds results.Opt
It turned out that Nim's Option type is broken for `not nil` and
`requiresInit` types. It will report an udesired warning due to
the way `none` is defined. The `Result` type doesn't suffer from
this problem, so I've transitioned some APIs in NBC to use the
new `results.Opt[T]` type (alias of `Result[T, void]`).

Perhaps we should renamed `Result` to `Res` to make the naming
more consistent and to allow the code to more easily fit in the
80 character per-line budget.
2020-04-22 15:43:26 +03:00
Jacek Sieka
ff755bbf75
change get/[] to always raise Defect and tryGet to do eh bridge mode (#30)
* also sprinkle mixin randomly across the codebase
2020-04-16 18:23:12 +02:00
Jacek Sieka
805ef4f1b2
result: cleanups
* fix defect raising without `$`
* doc updates
* better `?` that doesn't cause raises effect (it should, because of
FieldError but...)
2020-04-11 16:22:37 +02:00
Jacek Sieka
b06a5b6e32
result -> results (#27) 2020-04-07 11:43:07 +02:00