mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 18:07:59 +00:00
added map to sets
This commit is contained in:
@@ -241,3 +241,7 @@ proc `<=`*[A](s, t: TSet[A]): bool =
|
||||
|
||||
proc `==`*[A](s, t: TSet[A]): bool =
|
||||
s.counter == t.counter and s <= t
|
||||
|
||||
proc map*[A, B](data: TSet[A], op: proc (x: A): B {.closure.}): TSet[A] =
|
||||
result = initSet[B]()
|
||||
for i in data: result.incl(op(i))
|
||||
|
||||
13
tests/stdlib/tsets.nim
Normal file
13
tests/stdlib/tsets.nim
Normal file
@@ -0,0 +1,13 @@
|
||||
discard """
|
||||
output: '''true'''
|
||||
"""
|
||||
|
||||
import sets
|
||||
var
|
||||
a = initSet[int]()
|
||||
b = initSet[int]()
|
||||
|
||||
for i in 0..5: a.incl(i)
|
||||
for i in 1..6: b.incl(i)
|
||||
|
||||
echo map(a, proc(x: int): int = x + 1) == b
|
||||
Reference in New Issue
Block a user