Mark Spanbroek
6ef525cfe2
Reference types are handled by without statement with error
2024-01-09 16:52:39 +01:00
Mark Spanbroek
d463d491cc
Handle bind (=?) errors in without statements differently
...
Keeps track of the current error variable at compile time,
instead of using a pointer to the error variable at runtime.
Employs a trick with an unused type parameter to ensure that
invocations of the bindFailed() macro are expanded after
captureBindError() is expanded.
2024-01-09 16:45:32 +01:00
Tomasz Bekas
1f0afff48b
Support for .?[] operator on openArrays ( #52 )
...
* Support for .?[] operator on openArrays
* Operator .?[] evaluates openArray expression only once
* Fix for Nim 1.2.x
---------
Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
2023-11-20 14:58:49 +01:00
Nickolay Bukreyev
cdf639c4ea
Support binding closure iterators (except on Nim == 2.0)
...
See nim-lang/Nim#22932 .
2023-11-14 10:52:45 +01:00
Nickolay Bukreyev
fe47a19825
Create identifiers with genSym
2023-11-14 10:52:45 +01:00
Nickolay Bukreyev
440debc7c3
Accept only optional and reference types as RHS of =?
...
The fact that `option(x)` works for non-reference types (being an alias
for `some`) is an stdlib's design mistake that bites us here.
2023-11-14 10:52:45 +01:00
Mark Spanbroek
af4f194597
Fix tests for Nim < 2.0
2023-08-30 11:02:37 +02:00
Mark Spanbroek
5c8d422ac8
fix error binding in without statement on multiple threads
2023-08-30 11:02:37 +02:00
Tomasz Bekas
416b6dd566
Support seq indexing
2023-08-03 12:56:12 +02:00
Mark Spanbroek
1569ef4526
Fix tests for stew with Nim < 1.6
...
Stew now requires a Nim >= 1.6, so this disables
testing stew with earlier Nim versions.
2023-07-28 09:57:51 +02:00
Mark Spanbroek
3bce3088a7
Use root configuration when running tests
2023-07-03 11:16:56 +02:00
Mark Spanbroek
0d7ce8efde
Provide conversion to string $ for Results
2023-06-26 10:04:02 +02:00
Mark Spanbroek
b18444a6d0
Support renamed 'results' library
2023-06-05 17:26:46 +02:00
Mark Spanbroek
f957dd59d6
Fix tests on Nim 1.6.12
...
Ignore the nimble.lock at the root level when running tests
2023-06-05 17:26:46 +02:00
Eric Mastro
096ca864b0
tuple binding and unpacking support ( #29 )
...
* tuple binding and unpacking support
* support tuple binding in nim < 1.6
* Use ? instead of Option[] in tests
* Test binding of optional tuple, not just tuple
* Add tests for tuple unpacking of Result
* Remove unused import
* Rearrange tuple binding code
Introduce separate proc for creation of unpacking
statement.
Use `quote do` to make code as similar as possible
to the `bindLet` and `bindVar` templates.
* Add tests for failed tuple bindings
---------
Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
2023-02-14 09:56:32 +11:00
Mark Spanbroek
4d631b1ba9
Fix: ensure that options and results are only evaluated once
2022-09-28 11:36:28 +02:00
Mark Spanbroek
cbdd882b9f
Fix: unused variable
2022-08-10 13:35:47 +02:00
Mark Spanbroek
9e3a822877
Fix: disregard early symbol lookup for error variable
2022-08-10 13:35:47 +02:00
Mark Spanbroek
cfe17ca899
Fix error when using an existing name as error variable
2022-08-10 13:35:47 +02:00
Mark Spanbroek
90ea780ba9
Fix: nested without calls in generic code
2022-08-10 13:29:09 +02:00
Mark Spanbroek
4abeef5c36
Fix: without statement with error works in nested calls
2022-08-10 13:29:09 +02:00
Mark Spanbroek
13c7ff7671
Retrieve optional error from Result
2022-08-04 13:52:07 +02:00
Mark Spanbroek
0895a9c065
Fix: without statement with error works in generic code
2022-07-04 09:53:02 +02:00
Mark Spanbroek
a748d22350
Fix: ensure that overridden =? operator does not remain in scope
2022-01-12 17:54:24 +01:00
Mark Spanbroek
ef29000f94
Without statement for Results provides access to errors
2022-01-12 17:54:24 +01:00
Mark Spanbroek
92641b552d
Switch warningAsError only works for Nim >= 1.4.0
2021-12-04 17:56:14 +01:00
Mark Spanbroek
cfe4c6fc95
Ensure that =? works with types that do not have a default value
2021-12-04 17:26:08 +01:00
Mark Spanbroek
93f5c919fb
Ensure that optional binding works with closures
2021-05-31 16:24:21 +02:00
Mark Spanbroek
2700038316
Fix use of =? in generic code
2021-05-06 17:12:52 +02:00
Mark Spanbroek
8bf4f27f30
Avoid wrapping option in option when using .?[] operator
2021-05-04 16:17:09 +02:00
Mark Spanbroek
e8ab268758
Ensure that .? chains work in generic code
2021-05-04 15:55:05 +02:00
Mark Spanbroek
ee3d38d8d5
Fix typo
2021-04-19 15:52:15 +02:00
Mark Spanbroek
0569625f6a
Replace .get with operator !
...
Rationale: when looking for code that might crash it's
easier to spot exclamation marks than invocations of get.
2021-04-19 15:52:07 +02:00
Mark Spanbroek
fa56587bcd
Avoid wrapping option in option and result in result
2021-04-17 19:50:02 +02:00
Mark Spanbroek
d82581244c
Simplify
2021-04-17 19:25:33 +02:00
Mark Spanbroek
a8834aea66
Add missing test from readme
2021-04-16 12:27:43 +02:00
Mark Spanbroek
ef5f796463
without statement
2021-04-16 12:27:17 +02:00
Mark Spanbroek
827214f7a9
questionable/results also exports chaining and indexing
2021-04-16 12:10:10 +02:00
Mark Spanbroek
144c70580a
Calling success without arguments returns ?!void result
2021-04-15 11:04:26 +02:00
Mark Spanbroek
89850aab50
Makes |?, =? and .option compatible with other types of Result
2021-04-15 10:54:50 +02:00
Mark Spanbroek
fd73ff713f
Adds failure overload that uses result to determine type
2021-04-15 09:47:08 +02:00
Mark Spanbroek
86bfcc1a47
Use failure and success instead of ok and err
...
- Adds `isFailure` and `isSuccess`.
- No longer exports `ok`, `err`, `isErr` and `isOk`.
2021-04-15 09:39:37 +02:00
Mark Spanbroek
a2023ae18e
Documented how to work with =? in generic procs
2021-04-12 18:05:01 +02:00
Mark Spanbroek
3e92c35a85
Rename chaining and indexing operators
...
Chaining operator is now `.?`
Indexing operator is now `.?[]`
Reason: interoperability with the binding `=?` operator.
Chaining and indexing now have lower operator precedence
than binding, ensuring that expressions such as `if a =? b.?c`
work as expected.
2021-04-12 16:07:56 +02:00
Mark Spanbroek
40f5b4f1b8
Allow indexing of tables with ?[]
2021-03-18 17:58:48 +01:00
Mark Spanbroek
91f97c73ef
Evaluate =? expressions only once
2021-03-18 16:59:55 +01:00
Mark Spanbroek
aef59c42eb
Allow optional binding to vars
2021-03-18 09:50:06 +01:00
Mark Spanbroek
74c5089d49
Allow failure() to be called with string argument
2021-03-16 09:45:06 +01:00
Mark Spanbroek
21927f3c88
Replace "check false" with "fail"
2021-03-13 11:54:03 +01:00
Mark Spanbroek
43f09e8c86
Rename toOption() -> option()
...
To match the style of std/options, where option() is also used
to convert a ref to an Option.
2021-03-13 11:10:05 +01:00