Skip to content

Set expression¤

The set store unique items, without any particular order. Items in the set must be of the same type. The set is one of basic data structures provided by SP-Lang.

A set is best suited for a testing value for membership rather than retrieving a specific element from a set.


!SET: Set of items¤

Type: Implicit sequence, Mapping.

Synopsis:

!SET
- ...
- ...

Hint

Use !COUNT to determine number of items in the set.

There are several ways, how a set can be specified in SP-Lang:

Example

!SET
- "One"
- "Two"
- "Three"
- "Four"
- "Five"

Example

YAML unordered set:

!!set
? Yellow pork
? Pink grass
? White snow

Example

Concise set using YAML flow sequences:

!SET ["One", "Two", "Three", "Four", "Five"]

Example

The mapping form:

!SET
with:
- "One"
- "Two"
- "Three"
- "Four"
- "Five"

!IN: Membership test¤

Type: Mapping.

Synopsis:

!IN
what: <item>
where: <set>

Check if item is present in the set.

The expression !IN is described in the Comparisons chapter.

Example

!IN
what: 3
where:
  !SET
  with:
    - 1
    - 2
    - 5
    - 8