---
title: "Sequences"
url: https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences
language: ruby
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Sequences

Programming language: Ruby. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/python.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/swift.md).

A sequence is an ordered list of zero or more elements of the same type.

## Sequence Syntax

A sequence definition consists of the `sequence` keyword, its element type, and a name:

```slice
module M
{
    enum Fruit { Apple, Pear, Orange }
    sequence<Fruit> FruitPlatter;
}
```

The element type can be any Slice type, including a sequence:

```slice
module M
{
    sequence<FruitPlatter> FruitBanquet;
}
```

## Language Mapping

### Array Mapping

A Slice sequence maps to a Ruby array; the only exception is a sequence of bytes, which maps to a string. The use of a Ruby array means that the mapping does not generate a separate named type for a Slice sequence. It also means that you can take advantage of all the array functionality provided by Ruby. For example:

```slice
sequence<Fruit> FruitPlatter;
```

We can use the `FruitPlatter` sequence as shown below:

```ruby
platter = [ Fruit::Apple, Fruit::Pear ]
platter.push(Fruit::Orange)
```

### Mapping for Byte Sequences

A Ruby string can contain arbitrary 8-bit binary data, therefore it is a more efficient representation of a byte sequence than a Ruby array in both memory utilization and throughput performance.

When receiving a byte sequence (as the result of an operation, as an out parameter, or as a member of a data structure), the value is always represented as a string. When sending a byte sequence as an operation parameter or data member, the Ice runtime accepts both a string and an array of integers as legal values. For example, consider the following Slice definitions:

```slice
// Slice
sequence<byte> Data;

interface I
{
    void sendData(Data d);
    Data getData();
}
```

The interpreter session below uses these Slice definitions to demonstrate the mapping for a sequence of bytes:

```ruby
> proxy = ...
> proxy.sendData("\0\1\2\3")   # Send as a string
> proxy.sendData([0, 1, 2, 3]) # Send as an array
> d = proxy.getData()
> d.class
=> String
> d
=> "\000\001\002\003"
```

The two invocations of `sendData` are equivalent; however, the second invocation incurs additional overhead as the Ice runtime must validate the type and range of each array element.
