mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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:
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.
|
||||
|
||||
* `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.
|
||||
|
||||
* `std/setutils <setutils.html>`_
|
||||
This module adds functionality for the built-in ``set`` type.
|
||||
|
||||
|
||||
Collections
|
||||
@@ -115,7 +117,7 @@ Collections
|
||||
* `options <options.html>`_
|
||||
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.
|
||||
|
||||
* `sets <sets.html>`_
|
||||
@@ -131,7 +133,6 @@ Collections
|
||||
Nim hash table support. Contains tables, ordered tables, and count tables.
|
||||
|
||||
|
||||
|
||||
String handling
|
||||
---------------
|
||||
|
||||
@@ -196,7 +197,7 @@ Time handling
|
||||
-------------
|
||||
|
||||
* `std/monotimes <monotimes.html>`_
|
||||
The `monotimes` module implements monotonic timestamps.
|
||||
The ``monotimes`` module implements monotonic timestamps.
|
||||
|
||||
* `times <times.html>`_
|
||||
The ``times`` module contains support for working with time.
|
||||
@@ -234,8 +235,8 @@ Generic Operating System Services
|
||||
|
||||
* `streams <streams.html>`_
|
||||
This module provides a stream interface and two implementations thereof:
|
||||
the `FileStream` and the `StringStream` which implement the stream
|
||||
interface for Nim file objects (`File`) and strings. Other modules
|
||||
the ``FileStream`` and the ``StringStream`` which implement the stream
|
||||
interface for Nim file objects (``File``) and strings. Other modules
|
||||
may provide other implementations for this standard stream interface.
|
||||
|
||||
* `terminal <terminal.html>`_
|
||||
@@ -296,7 +297,7 @@ Internet Protocols and Support
|
||||
module.
|
||||
|
||||
* `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>`_
|
||||
This module implements helpers for CGI applications.
|
||||
@@ -411,7 +412,6 @@ Generators
|
||||
that generates a string with its HTML representation.
|
||||
|
||||
|
||||
|
||||
Hashing
|
||||
-------
|
||||
|
||||
@@ -435,7 +435,6 @@ Hashing
|
||||
This module implements a sha1 encoder and decoder.
|
||||
|
||||
|
||||
|
||||
Miscellaneous
|
||||
-------------
|
||||
|
||||
@@ -536,6 +535,7 @@ UNIX specific
|
||||
* `posix_utils <posix_utils.html>`_
|
||||
Contains helpers for the POSIX standard or specialized for Linux and BSDs.
|
||||
|
||||
|
||||
Regular expressions
|
||||
-------------------
|
||||
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## This module adds functionality to the built-in `set` type.
|
||||
## See also std/packedsets, std/sets
|
||||
## This module adds functionality for the built-in `set` type.
|
||||
##
|
||||
## 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
|
||||
@@ -18,14 +22,15 @@ import typetraits
|
||||
]#
|
||||
|
||||
template toSet*(iter: untyped): untyped =
|
||||
## Return a built-in set from the elements of iterable `iter`
|
||||
runnableExamples:
|
||||
## Returns a built-in set from the elements of the iterable `iter`.
|
||||
runnableExamples:
|
||||
assert "helloWorld".toSet == {'W', 'd', 'e', 'h', 'l', 'o', 'r'}
|
||||
assert toSet([10u16, 20, 30]) == {10u16, 20, 30}
|
||||
assert [30u8, 100, 10].toSet == {10u8, 30, 100}
|
||||
assert toSet(@[1321i16, 321, 90]) == {90i16, 321, 1321}
|
||||
assert toSet([false]) == {false}
|
||||
assert toSet(0u8..10) == {0u8..10}
|
||||
|
||||
var result: set[elementType(iter)]
|
||||
for x in iter:
|
||||
incl(result, x)
|
||||
|
||||
Reference in New Issue
Block a user