Add std/setutils to lib.rst (#16791)
* Add std/setutils to lib.rst Improve doc comments for setutils * Adhere to the RST spec Use no UFCS in toSet
This commit is contained in:
parent
f1d165adf2
commit
72bbd07ec1
2 changed files with 19 additions and 14 deletions
18
doc/lib.rst
18
doc/lib.rst
|
|
@ -86,9 +86,11 @@ Algorithms
|
||||||
This module implements some common generic algorithms like sort or binary search.
|
This module implements some common generic algorithms like sort or binary search.
|
||||||
|
|
||||||
* `sequtils <sequtils.html>`_
|
* `sequtils <sequtils.html>`_
|
||||||
This module implements operations for the built-in seq type
|
This module implements operations for the built-in ``seq`` type
|
||||||
which were inspired by functional programming languages.
|
which were inspired by functional programming languages.
|
||||||
|
|
||||||
|
* `std/setutils <setutils.html>`_
|
||||||
|
This module adds functionality for the built-in ``set`` type.
|
||||||
|
|
||||||
|
|
||||||
Collections
|
Collections
|
||||||
|
|
@ -115,7 +117,7 @@ Collections
|
||||||
* `options <options.html>`_
|
* `options <options.html>`_
|
||||||
The option type encapsulates an optional value.
|
The option type encapsulates an optional value.
|
||||||
|
|
||||||
* `packedsets <packedsets.html>`_
|
* `std/packedsets <packedsets.html>`_
|
||||||
Efficient implementation of a set of ordinals as a sparse bit set.
|
Efficient implementation of a set of ordinals as a sparse bit set.
|
||||||
|
|
||||||
* `sets <sets.html>`_
|
* `sets <sets.html>`_
|
||||||
|
|
@ -131,7 +133,6 @@ Collections
|
||||||
Nim hash table support. Contains tables, ordered tables, and count tables.
|
Nim hash table support. Contains tables, ordered tables, and count tables.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String handling
|
String handling
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|
@ -196,7 +197,7 @@ Time handling
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
* `std/monotimes <monotimes.html>`_
|
* `std/monotimes <monotimes.html>`_
|
||||||
The `monotimes` module implements monotonic timestamps.
|
The ``monotimes`` module implements monotonic timestamps.
|
||||||
|
|
||||||
* `times <times.html>`_
|
* `times <times.html>`_
|
||||||
The ``times`` module contains support for working with time.
|
The ``times`` module contains support for working with time.
|
||||||
|
|
@ -234,8 +235,8 @@ Generic Operating System Services
|
||||||
|
|
||||||
* `streams <streams.html>`_
|
* `streams <streams.html>`_
|
||||||
This module provides a stream interface and two implementations thereof:
|
This module provides a stream interface and two implementations thereof:
|
||||||
the `FileStream` and the `StringStream` which implement the stream
|
the ``FileStream`` and the ``StringStream`` which implement the stream
|
||||||
interface for Nim file objects (`File`) and strings. Other modules
|
interface for Nim file objects (``File``) and strings. Other modules
|
||||||
may provide other implementations for this standard stream interface.
|
may provide other implementations for this standard stream interface.
|
||||||
|
|
||||||
* `terminal <terminal.html>`_
|
* `terminal <terminal.html>`_
|
||||||
|
|
@ -296,7 +297,7 @@ Internet Protocols and Support
|
||||||
module.
|
module.
|
||||||
|
|
||||||
* `asyncstreams <asyncstreams.html>`_
|
* `asyncstreams <asyncstreams.html>`_
|
||||||
This module provides `FutureStream` - a future that acts as a queue.
|
This module provides ``FutureStream`` - a future that acts as a queue.
|
||||||
|
|
||||||
* `cgi <cgi.html>`_
|
* `cgi <cgi.html>`_
|
||||||
This module implements helpers for CGI applications.
|
This module implements helpers for CGI applications.
|
||||||
|
|
@ -411,7 +412,6 @@ Generators
|
||||||
that generates a string with its HTML representation.
|
that generates a string with its HTML representation.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Hashing
|
Hashing
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
@ -435,7 +435,6 @@ Hashing
|
||||||
This module implements a sha1 encoder and decoder.
|
This module implements a sha1 encoder and decoder.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Miscellaneous
|
Miscellaneous
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
@ -536,6 +535,7 @@ UNIX specific
|
||||||
* `posix_utils <posix_utils.html>`_
|
* `posix_utils <posix_utils.html>`_
|
||||||
Contains helpers for the POSIX standard or specialized for Linux and BSDs.
|
Contains helpers for the POSIX standard or specialized for Linux and BSDs.
|
||||||
|
|
||||||
|
|
||||||
Regular expressions
|
Regular expressions
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,14 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
## This module adds functionality to the built-in `set` type.
|
## This module adds functionality for the built-in `set` type.
|
||||||
## See also std/packedsets, std/sets
|
##
|
||||||
|
## See also
|
||||||
|
## ========
|
||||||
|
## * `std/packedsets <packedsets.html>`_
|
||||||
|
## * `std/sets <sets.html>`_
|
||||||
|
|
||||||
import typetraits
|
import std/typetraits
|
||||||
|
|
||||||
#[
|
#[
|
||||||
type SetElement* = char|byte|bool|int16|uint16|enum|uint8|int8
|
type SetElement* = char|byte|bool|int16|uint16|enum|uint8|int8
|
||||||
|
|
@ -18,14 +22,15 @@ import typetraits
|
||||||
]#
|
]#
|
||||||
|
|
||||||
template toSet*(iter: untyped): untyped =
|
template toSet*(iter: untyped): untyped =
|
||||||
## Return a built-in set from the elements of iterable `iter`
|
## Returns a built-in set from the elements of the iterable `iter`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
assert "helloWorld".toSet == {'W', 'd', 'e', 'h', 'l', 'o', 'r'}
|
assert "helloWorld".toSet == {'W', 'd', 'e', 'h', 'l', 'o', 'r'}
|
||||||
assert toSet([10u16, 20, 30]) == {10u16, 20, 30}
|
assert toSet([10u16, 20, 30]) == {10u16, 20, 30}
|
||||||
assert [30u8, 100, 10].toSet == {10u8, 30, 100}
|
assert [30u8, 100, 10].toSet == {10u8, 30, 100}
|
||||||
assert toSet(@[1321i16, 321, 90]) == {90i16, 321, 1321}
|
assert toSet(@[1321i16, 321, 90]) == {90i16, 321, 1321}
|
||||||
assert toSet([false]) == {false}
|
assert toSet([false]) == {false}
|
||||||
assert toSet(0u8..10) == {0u8..10}
|
assert toSet(0u8..10) == {0u8..10}
|
||||||
|
|
||||||
var result: set[elementType(iter)]
|
var result: set[elementType(iter)]
|
||||||
for x in iter:
|
for x in iter:
|
||||||
incl(result, x)
|
incl(result, x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue