This module adds functionality for the built-in set type.
func complement[T](s: set[T]): set[T] {.inline.}a. Example:
type Colors = enum
red, green = 3, blue
assert complement({red, blue}) == {green}
assert complement({red, green, blue}).card == 0
assert complement({range[0..10](0), 1, 2, 3}) == {range[0..10](4), 5, 6, 7, 8, 9, 10}
assert complement({'0'..'9'}) == {0.char..255.char} - {'0'..'9'} Source Edit template toSet(iter: untyped): untyped
iter. Example:
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} Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/setutils.html