Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add std/setutils to lib.rst #16791

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions doc/lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>`_
Expand All @@ -131,7 +133,6 @@ Collections
Nim hash table support. Contains tables, ordered tables, and count tables.



String handling
---------------

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>`_
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -411,7 +412,6 @@ Generators
that generates a string with its HTML representation.



Hashing
-------

Expand All @@ -435,7 +435,6 @@ Hashing
This module implements a sha1 encoder and decoder.



Miscellaneous
-------------

Expand Down Expand Up @@ -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
-------------------

Expand Down
15 changes: 10 additions & 5 deletions lib/std/setutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@
# 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
## The allowed types of a built-in set.
]#

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)
Expand Down