Module tuples

Macros

macro projectTo(t: typed; fields: varargs[untyped]): untyped
Allows to project a given tuple to a subset of its fields, by keeping only the specified fields.   Source Edit
macro projectAway(t: typed; fields: varargs[untyped]): untyped
Allows to project a given tuple to a subset of its fields, by removing the specified fields.   Source Edit
macro addFields(t: typed; fields: varargs[untyped]): untyped
Returns a new tuple expression, containing all fields of the given tuple, plus new fields as specified in the varargs. New field expressions are specified as colon expressions, i.e.: .. code-block:: nim

let t = (x: 1.0, y: 1.0) let tExtended = addFields(t, length: sqrt(t.x*t.x + t.y*t.y))

Notes:

  • The expression must use the fully qualified name (like t.x), not just the field names (x).
  • The syntax t.addFields(length: sqrt(t.x*t.x + t.y*t.y) is currently not yet supported by the compiler.
  Source Edit
macro addField(t: typed; field: untyped): untyped
Returns a new tuple expression, containing all fields of the given tuple, plus a new field as specified in field. New field expressions are specified as colon expressions, i.e.: .. code-block:: nim

let t = (x: 1.0, y: 1.0) let tExtended = addField(t, length: sqrt(t.x*t.x + t.y*t.y))

Notes:

  • The expression must use the fully qualified name (like t.x), not just the field names (x).
  • The syntax t.addFields(length: sqrt(t.x*t.x + t.y*t.y) is currently not yet supported by the compiler.
  Source Edit
macro determineType[](ta, tb: typed; on: static[openArray[string]]): untyped
  Source Edit
macro mergeTuple[](a: tuple; b: tuple; on: static[openArray[string]]): untyped
Merges the fields of a tuple a and b into a new named tuple. The field names are merged using the logic:
  • If a field occurs either in a or b, the field is merged keeping its original name.
  • If tuple a and b both have a field with the same name fieldName, they will be renamed to fieldNameA and fieldNameB (if such a field already exists, there would be a compiler error).
  • If a.fieldName and b.fieldName are referring to the same information (e.g. if fieldName is part of a join condition), the field duplication can be avoided by specifying the field in the on clause. In this case the result would only contain the field fieldName, and the value is taked from tuple a.
  Source Edit
macro tupleMatches[](a: tuple; b: tuple; on: static[openArray[string]]): untyped
  Source Edit