Commit Graph

28 Commits

Author SHA1 Message Date
Timothee Cour
578d1ee751 std/options: $some(3) is now "some(3)", etc. (#17147)
* std/options: $some(3) is now "some(3)", not "Some(3)", `$none(int)` is now `"none(int)"` instead of `"None[int]"`

* fix tests

* disable optionsutils
2021-02-24 22:17:16 +00:00
konsumlamm
05711d95e0 Add example for pattern matching on options (#17120)
* Add example for pattern matching on options

* Use code-block

* Apply suggestions

* Use block comments

* Fix example
2021-02-22 11:16:15 +01:00
konsumlamm
f400b5c26b Improve documentation for options (#17036) 2021-02-18 02:10:50 -08:00
flywind
d447c0fe3f use typeof instead type (#16962) 2021-02-08 09:46:07 +01:00
flywind
805917768d use runnableExamples in options (#16503) 2020-12-30 16:26:49 +01:00
flywind
cbc793b30b move tests to testament (#16101)
* move tests to testament

* minor

* fix random

* disable test random
2020-11-24 19:06:41 +01:00
Ivan Bobev
ccd77b42af Add some enhancements to jsonutils.nim (#15133)
* Add some enhancements to `jsonutils.nim`

* Use `jsonutils.nim` hookable API to add a possibility to deserialize
  JSON arrays directly to `HashSet` and `OrderedSet` types and
  respectively to serialize those types to JSON arrays.

* Also add a possibility to deserialize JSON `null` objects to Nim
  option objects and respectively to serialize Nim option object to JSON
  object if some or to JSON `null` object if none.

* Move serialization/deserialization functionality for `Table` and
  `OrderedTable` types from `jsonutils.nim` to `tables.nim` via the
  hookable API.

* Add object `jsonutils.Joptions` and parameter from its type to
  `jsonutils.fromJson` procedure to control whether to allow
  deserializing JSON objects to Nim objects when the JSON has some
  extra or missing keys.

* Add unit tests for the added functionalities to `tjsonutils.nim`.

* improve fromJsonFields

* Add changelog entry for the jsonutils enhancements

* Add TODO in `jsonutils.nim`

* Added an entry to "Future directions" section in `jsonutils.nim` as
  suggestion for future support of serialization and de-serialization of
  nested variant objects.

* Added currently disabled test case in `tjsonutils.nim` for testing
  serialization and de-serialization of nested variant objects.

* Move JSON hooks to `jsonutils.nim`

Move `fromJsonHook` and `toJsonHook` procedures for different types to
`jsonutils.nim` module to avoid a dependency of collections modules to
the `json.nim` module.

The hooks are removed from the following modules:

  * `tables.nim`

  * `sets.nim`

  * `options.nim`

  * `strtabs.nim`

* Add some tests about `StringTableRef`

Add tests for `StringTableRef`'s `fromJsonHook` and `toJsonHook` to
`tjsonutils.nim`.

* Disable a warning in `jsonutils.nim`

Mark `fun` template in `jsonutils` module with `{.used.}` pragma in
order to disable `[XDeclaredButNotUsed]` hint. The template is actually
used by the `initCaseObject` macro in the same module.

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
2020-09-09 14:18:59 +02:00
Mamy Ratsimbazafy
07d82b5cc4 Use more lent in options (#15208) 2020-08-24 08:05:17 +02:00
Ivan Bobev
cc65ae6011 Change UnpackError with UnpackDefect (#14457)
* Change `UnpackError` with `UnpackDefect`

The deprecation warning for `UnpackError` exception raised by some
`inline` procedures in the Nim standard library propagates to the user
code. If the user code has a requirement for building without warnings
this is a problem for the successful execution of the tests. In order
to resolve this, all occurrences of `UnpackError` in the Nim code base
are changed to `UnpackDefect`. Only the type alias is retained to not
break other people's user code since `UnpackError` is exported type.

* Remove the catching of `UnpackDefect`

Defect exceptions should not be cached, because they indicate problem in
the API usage. The code in `nimblesocket.nim` is rewritten to first
check whether there is a value set into the `knownDomain` variable from
the `Option` type before usage.
2020-05-27 08:34:13 +02:00
cooldome
6635874a85 make get for options use lent T (#14442)
Co-authored-by: cooldome <ariabushenko@bk.ru>
2020-05-25 15:31:02 +02:00
Mamy Ratsimbazafy
f71f8b0239 The whole options module should be inline (#14417) [backport:1.2]
* The whole options module should be inline

* Use inline per proc and tag `lent` where appropriate

* Remove lent annotation (failing at compiletime)
2020-05-21 17:52:40 +02:00
Jacek Sieka
7d6cbf290a Error -> Defect for defects (#13908)
* Error -> Defect for defects

The distinction between Error and Defect is subjective,
context-dependent and somewhat arbitrary, so when looking at an
exception, it's hard to guess what it is - this happens often when
looking at a `raises` list _without_ opening the corresponding
definition and digging through layers of inheritance.

With the help of a little consistency in naming, it's at least possible
to start disentangling the two error types and the standard lib can set
a good example here.
2020-04-28 19:56:01 +02:00
hlaaftana
1276e386fe Consider proc as a pointer type in options (#13460)
* Consider proc as a pointer type in options

* Add version annotation for SomePointer having proc in options

* Log procs as pointers for options in changelog
2020-02-21 23:14:55 +01:00
narimiran
5732bb41ef [backport] run nimpretty on the remaining files 2019-09-30 13:58:17 +02:00
Yuriy Glukhov
d53ab9e5c8 Prevent options from calling custom ref == operators (#10745) 2019-02-26 15:43:34 +01:00
Miran
cedf784751 better docs: options (#10720) 2019-02-22 12:28:00 +01:00
Oscar Nihlgård
0a749f1a37 Make options.UnpackError inherit from system.Defect 2018-12-08 10:04:53 +01:00
Arne Döring
ce4383be3b fixes #8658; addQuoted on Option[T] (#8659) 2018-08-17 01:24:28 +02:00
Dominik Picheta
feda366d86 Adds get for Option[T]. (#8462) 2018-08-14 01:09:08 +02:00
Quelklef
ac3c4a94ad Fixed $ on None[T] for T with .name (#8293) 2018-07-12 11:01:48 +02:00
alaviss
26d89fa09c options: use isSome (#7782)
Fixes #7780
2018-05-06 10:55:19 +02:00
hlaaf
38b2596ff9 Add none[T]() as alias to none(T) (#7512)
* Add none[T]() as alias to none(T)

* Add tests for none[T]

* this test shouldn't work anyway
2018-04-16 21:01:37 +02:00
Arne Döring
e7edc7ec7f option optimization (#6253) 2018-04-11 16:50:27 +02:00
Euan T
4617114453 Fix documentation for the $ proc on an option (#6449) 2017-10-02 16:11:53 +02:00
Zach Smith
7abad507c9 Add flatMap operator to Options (#6404)
* Add >>= operator to Options

* options.bind callback signature: A -> Option[B]

* Use `flatMap` as the name of the Option bind operation.

* Rename Options test "bind" to "flatMap"

* CR from @dom96: Remove spaces inside of check() call
2017-09-27 21:55:55 +01:00
def
93e01da671 Fix options module to use new import name 2015-11-23 16:30:18 +01:00
Nycto
6fa01e3490 Extend option functionality 2015-09-23 08:52:51 -07:00
Flaviu Tamas
0479831fb0 Rename optionals module to options 2015-05-26 16:48:17 -04:00