summaryrefslogtreecommitdiff
path: root/docs/type_system/union.md
blob: 7d0c79869d37a6dc51fef8fe81479c90714ea2e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Union

---

```text
Union_class `alias Enum[.container; .transient]

Union[Union_class; TYPE.symbol; ...]
```

```text
u : Union[I64.a; I64.b; I64.c] $ (.c : 5) // defaults to Union[.container; ...]

# u {
    .c { c ... }[c]
    { ... } // default
}
```

# Transient Unions

Can only be retuned from functions and operations. The inner value must be moved out

## Alias

```text
Result[ANY] `alias Union[.transient; ANY.value; Error.error]

Option[ANY] `alias Union[.transient; ANY.some; Void.none]

Next[Any] `alias Union[.transient; ANY.value; Void.done; Error.error]
```

## Default Operation

When a transient union is assigned the first type specified is moved out.

If the type is not the first specified a result with an error is returned to the parent function

```text
z : x / y // Result[Int[...]]
z // is value if y is not zero
```
## Operators

### \`value

### \`error

### \`some

### \`none