fixed a bug in map for sets
This commit is contained in:
parent
56c41ae140
commit
e8c87d070a
2 changed files with 7 additions and 3 deletions
|
|
@ -242,6 +242,6 @@ 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] =
|
||||
proc map*[A, B](data: TSet[A], op: proc (x: A): B {.closure.}): TSet[B] =
|
||||
result = initSet[B]()
|
||||
for i in data: result.incl(op(i))
|
||||
for item in data: result.incl(op(item))
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
discard """
|
||||
output: '''true'''
|
||||
output: '''true
|
||||
true'''
|
||||
"""
|
||||
|
||||
import sets
|
||||
var
|
||||
a = initSet[int]()
|
||||
b = initSet[int]()
|
||||
c = initSet[string]()
|
||||
|
||||
for i in 0..5: a.incl(i)
|
||||
for i in 1..6: b.incl(i)
|
||||
for i in 0..5: c.incl($i)
|
||||
|
||||
echo map(a, proc(x: int): int = x + 1) == b
|
||||
echo map(a, proc(x: int): string = $x) == c
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue