Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Function

Array literals

[a, b, c] · [ new GridColumn<User> { Name = "Email", Value = u => u.Email }, … ]

An array literal [a, b, c] is a value: a list you can return, assign, pass as an argument, or supply as a UI prop. Its element type is inferred from the items. Object literals inside it (new T { … }) are plain data, so a render prop like columns: [ new GridColumn<User> { Name = "Email", Value = u => u.Email } ] is fully expressible.

preview2 examples compiled by CIfunctiontypesauthoringcollections

Summary#

An array literal [a, b, c] is a value expression — a list you can return, assign to a local, pass as an argument, or hand to a UI control as a prop. The element type is inferred from the items (a homogeneous list is the common case). Because object literals (new T { … }) are plain data, a list of them is a first-class value too — so a UI prop like columns: [ new GridColumn<User> { Name = "Email", Value = u => u.Email } ] is expressed directly, no workaround.

Signature#

[1, 2, 3]                                     // int[]
["Email", "DisplayName"]                       // string[]
[ new GridColumn<User> { Name = "Email", Value = u => u.Email } ]   // GridColumn<User>[]
[]                                             // an empty list

Description#

  • A value, anywhere a value fits — return it, assign it (var xs = [1, 2, 3];), pass it as an argument, or use it as a render/state value in a component.
  • Element type is inferred from the items; a list of new GridColumn<User> { … } is a GridColumn<User>[], matching a prop declared GridColumn<T>[].
  • Object literals inside are pure data. In a render position a new T { … } builds a plain data object (it is not a stored row — that is what a new T { … } inside an action body does). This is why a control's columns prop takes [ new GridColumn<T> { … } ] cleanly.
  • Distinct from set-membership. Testing membership is written [a, b].Contains(x) (or x in [a, b]), which the compiler lowers to a set test — separate from using [a, b] as a value.

Examples#

int[] Small() { return [1, 2, 3]; }
string[] Names() { var xs = ["Ada", "Grace"]; return xs; }

Supplying a control's typed columns from an array of object literals (a UI prop):

entity User {
  [Required, MaxLength(200)] string Email;
  [Required, MaxLength(120)] string DisplayName;
  security { allow read when IsAuthenticated; }
}

[Page("/users")] [Render(CSR)]
component UsersPage() {
  var users = User.ToList();
  render {
    DataGrid(
      label: "Users",
      rows: users,
      columns: [
        new GridColumn<User> { Name = "Email", Label = "Email", Value = u => u.Email },
        new GridColumn<User> { Name = "DisplayName", Label = "Name", Value = u => u.DisplayName }
      ]
    );
  }
}

See also#

Related

List indexer

Positional get/set on a List<T> by integer index, exactly like C#'s List<T>.this[int]. The index must be an integer…

List OrderBy (in-memory)

Sort a local List<T> in memory by a key selector, returning a NEW sorted List<T> (the source is untouched). Ascending…

control — foreign UI controls (charts, grids, maps)

A `control` block declares the contract of a foreign UI widget — a chart, a data grid, a map — that a small JavaScript…