added map to sets
This commit is contained in:
parent
5d93957048
commit
0b5c14962e
2 changed files with 17 additions and 0 deletions
|
|
@ -241,3 +241,7 @@ proc `<=`*[A](s, t: TSet[A]): bool =
|
||||||
|
|
||||||
proc `==`*[A](s, t: TSet[A]): bool =
|
proc `==`*[A](s, t: TSet[A]): bool =
|
||||||
s.counter == t.counter and s <= t
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue