same

same, selector

def process same(value: any): any

Returns value when all non-empty group elements are equal. Empty groups return the default value for the data type (or a custom default).

Example

table T = with
  [| as Item, as Group |]
  [| 1, "a" |]
  [| 1, "a" |]
  [| 2, "b" |]

table G[g] = with
  [| as g |]
  [| "a" |]
  [| "b" |]
  [| "c" |]

G.Value = same(T.Item) by T.Group at G.g default -1

show table "Same" with
  g
  G.Value

This outputs the following table:

g Value
a 1
b 2
c -1

Errors

Fails when the group is non-empty and contains distinct values.

See also

User Contributed Notes
0 notes + add a note