The table below lists the functions available in the SequenceFunctions namespace of the Standard Libraries.

FunctionExampleDescription

abstract function # {
    in ref feature seq[0..*] : Anything
    in ref feature index[1] : Positive
}


package IndexTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);

  attribute indexTest = a#(3);
}

Output

>> indexTest 
5

 

  • Returns the element at the specified index position in the sequence. Indexing starts at 1.
  • Related:

abstract function equals {
    in ref feature x[0..*] : Anything
    in ref feature y[0..*] : Anything
}

package EqualsTest {
  private import SequenceFunctions::*;
  attribute a1 = (10, 20);
  attribute b1 = (20, 10);
  attribute c1 = (20, 10);



  attribute equalsTest1 = equals(a1, b1);
  attribute equalsTest2 = equals(b1, c1);
}

Output

 >> equalsTest1 
false  

>> equalsTest2 
true

 

  • Returns true if sequences x and y contain the same elements in the same order.

abstract function same {
    in ref feature x[0..*] : Anything
    in ref feature y[0..*] : Anything
}


package SameTest {
  private import SequenceFunctions::*;
  attribute a1 = (10, 20);
  attribute b1 = (20, 10);

  attribute sameTest1 = same(a1, b1);
  attribute sameTest2 = same(a1, a1);
}

Output

 >> sameTest1 
false  

>> sameTest2 
true

 

  • Returns true if sequences x and y refer to the same instance.

abstract function size {
    in ref feature seq[0..*] : Anything
}

 

package SizeTest {
  private import SequenceFunctions::*;
  attribute a = (10, 20, 30);

  attribute sizeTest = size(a);
}

Output

 >> sizeTest 

 

  • Returns the number of elements in the sequence x.

abstract function isEmpty {
    in ref feature seq[0..*] : Anything
}

 

package IsEmptyTest {
  private import SequenceFunctions::*;
  attribute a = (10, 20, 30);

  attribute isEmptyTest = isEmpty(a);
}

Output

 >> isEmptyTest 
false

 

  • Returns true if the sequence x has no elements.

abstract function notEmpty {
    in ref feature seq[0..*] : Anything
}

 

package NotEmptyTest {
  private import SequenceFunctions::*;
  attribute a = (10, 20, 30);

  attribute notEmptyTest = notEmpty(a);
}

Output

 >> notEmptyTest 
true

 

  • Returns true if the sequence x contains one or more elements.

abstract function includes {
    in ref feature seq1[0..*] : Anything
    in ref feature seq2[0..*] : Anything
}

 

package IncludesTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 3);
  attribute b = (3, 2);

  attribute includesTest = includes(a, b);
}

Output

 >> includesTest 
true 

 

  • Returns true if sequence x contains elements in sequence y.

abstract function includesOnly {
    in ref feature seq1[0..*] : Anything
    in ref feature seq2[0..*] : Anything
}

 

package IncludesOnlyTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 3);
  attribute b = (4, 3, 2);

  attribute includesOnlyTest = includesOnly(a, b);
}

Output

 >> includesOnlyTest 
true 

 

  • Returns true if all elements of sequence x are included in sequence y.

abstract function excludes {
    in ref feature seq1[0..*] : Anything
    in ref feature seq2[0..*] : Anything
}

 

package ExcludesTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 3);
  attribute b = 1;

  attribute excludesTest = excludes(a, b);
}

Output

 >> excludesTest 
true 

 

  • Returns true if none of the elements in sequence y are present in sequence x.

abstract function union {
    in ref feature seq1[0..*] : Anything
    in ref feature seq2[0..*] : Anything
}

 

package UnionTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 3);
  attribute b = 1;

  attribute unionTest = union(a, b);
}

Output

 >> unionTest 
4
2
3
1

 

  • Returns a new sequence containing all elements from sequences x and y.

abstract function intersection {
    in ref feature seq1[0..*] : Anything
    in ref feature seq2[0..*] : Anything
}

 

package IntersectionTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 3);
  attribute b = 2;

  attribute intersectionTest = intersection(a, b);
}

Output

 >> intersectionTest 
2

 

  • Returns a sequence containing elements common to both sequences x and y.

abstract function including {
    in ref feature seq[0..*] : Anything
    in ref feature values[0..*] : Anything
}

 

package IncludingTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2);
  attribute b = 2;

  attribute includingTest = including(a, b);
}

Output

 >> includingTest 
4
2

 

  • Returns a new sequence with element y appended to the end of sequence x.

abstract function includingAt {
    in ref feature seq[0..*] : Anything
    in ref feature values[0..*] : Anything
    in ref feature index[1] : Positive
}

 

package IncludingAtTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2);
  attribute b = 5;

  attribute includingAtTest = includingAt(a, b, 2);
}

Output

 >> includingAtTest 
4
5
2

 

  • Returns a new sequence with element y inserted into sequence x at position i.

abstract function excluding {
    in ref feature seq[0..*] : Anything
    in ref feature values[0..*] : Anything
}

 

package ExcludingTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2);
  attribute b = 2;

  attribute excludingTest = excluding(a, b);
}

Output

 >> excludingTest 
4

 

  • Returns a new sequence with all occurrences of element y removed from sequence x.

abstract function excludingAt {
    in ref feature seq[0..*] : Anything
    in ref feature startIndex[1] : Positive
    in ref feature endIndex[1] : Positive
}

 

package ExcludingAtTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);
  attribute b = 2;

  attribute excludingAtTest = excludingAt(a, b, 2);
}

Output

 >> excludingAtTest 
4
5
1

 

  • Returns a new sequence with elements removed from sequence x between indexes y and z.

abstract function subsequence {
    in ref feature seq[0..*] : Anything
    in ref feature startIndex[1] : Positive
    in ref feature endIndex[1] : Positive
}

 

package SubsequenceTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);

  attribute subSequenceTest = subsequence(a, 2, 3);
}

Output

 >> subSequenceTest 
2
5

 

  • Returns a new sequence containing elements from sequence x starting at y and ending at z.

abstract function head {
    in ref feature seq[0..*] : Anything
}

 

package HeadTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);

  attribute headTest = head(a);
}

Output

 >> headTest 
4

 

  • Returns the first element of sequence x.

abstract function tail {
    in ref feature seq[0..*] : Anything
}

 

package TailTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);

  attribute tailTest = tail(a);
}

Output

 >> tailTest 
2
5
1

 

  • Returns a sequence containing all elements of x except the first.

abstract function last {
    in ref feature seq[0..*] : Anything
}

 

package LastTest {
  private import SequenceFunctions::*;
  attribute a = (4, 2, 5, 1);

  attribute lastTest = last(a);
}

Output

 >> lastTest 
1

 

  • Returns the last element of sequence x.