# dista.seq

> A module of Dista's API.

`Seq[T]`: a list that goes through the codec.

`List` can't be encoded by reflection, because reflection can't recover its
element type. `Seq[T]` carries `T` as a parameter, so it can encode each
element with the generic codec:

```mojo
def total(xs: Seq[Int]) -> Int:
    var t = 0
    for i in range(len(xs)):
        t += xs[i]
    return t

comptime Total = Task[Seq[Int], Int, total]
```

On the wire a `Seq` is an 8-byte count, then each element's encoding. That is
also how the runtime builds one from a list of `ObjectRef`s: the count, then
each result's bytes as they arrived, without decoding them.

## Structs

### `Seq`

```mojo
struct Seq[T: Copyable & Deinitable]
```

A list of `T` that tasks can take and return.

Implements: `Codec`, `Copyable`, `Movable`, `Sized`

Fields:

- `items: List[T]`

#### `__init__`

```mojo
def __init__(out self)
```

```mojo
def __init__(out self, var items: List[T])
```

#### `__getitem__`

```mojo
def __getitem__(self, i: Int) -> T
```

A copy of element `i`. Use `items` to borrow instead.

#### `append`

```mojo
def append(mut self, var value: T)
```

#### `__len__`

```mojo
def __len__(self) -> Int
```

#### `encode`

```mojo
def encode(self, mut out: List[UInt8])
```

#### `decode`

```mojo
def decode(buf: Span[UInt8], mut pos: Int) -> Self
```
