Hi,
In the template I am trying to evaluate the boolean expression that is defined
in terms tuple variable names. With one variable it is clear, we have a number
of examples in the standard library: mapIt, allIt, filterIt and etc. But I am
struggling to extend this approach for multiple variables where variable names
come from tuple definition.
Basically, what I am trying to achieve is the following, but it doesn't
compile. The injected variables get out of scope before they can be used.
type DataTable = tuple
id : seq[int]
name : seq[string]
age: seq[Natural]
proc len(dt: DataTable) : Natural =
for f in fields(dt):
return f.len
return 0
template mask(dt : DataTable, expr : untyped) : seq[bool] =
var result = newSeq[bool](dt.len)
for i in 0 ..< dt.len:
for name, value in fieldPairs(t):
let `name` {.inject.} = value[i]
result[i] = expr
result
echo mask(x, age >= 15 and isAlphaNumeric(name))
Thank you