diff --git a/doc/lib.rst b/doc/lib.rst index cbab64775dcaf..6895d8efd0fa7 100644 --- a/doc/lib.rst +++ b/doc/lib.rst @@ -86,9 +86,11 @@ Algorithms This module implements some common generic algorithms like sort or binary search. * `sequtils `_ - 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 `_ + This module adds functionality for the built-in ``set`` type. Collections @@ -115,7 +117,7 @@ Collections * `options `_ The option type encapsulates an optional value. -* `packedsets `_ +* `std/packedsets `_ Efficient implementation of a set of ordinals as a sparse bit set. * `sets `_ @@ -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 `_ - The `monotimes` module implements monotonic timestamps. + The ``monotimes`` module implements monotonic timestamps. * `times `_ The ``times`` module contains support for working with time. @@ -234,8 +235,8 @@ Generic Operating System Services * `streams `_ 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 `_ @@ -296,7 +297,7 @@ Internet Protocols and Support module. * `asyncstreams `_ - This module provides `FutureStream` - a future that acts as a queue. + This module provides ``FutureStream`` - a future that acts as a queue. * `cgi `_ 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 `_ Contains helpers for the POSIX standard or specialized for Linux and BSDs. + Regular expressions ------------------- diff --git a/lib/std/setutils.nim b/lib/std/setutils.nim index c6385180e6261..215c7a76a7dab 100644 --- a/lib/std/setutils.nim +++ b/lib/std/setutils.nim @@ -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 `_ +## * `std/sets `_ -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)