Skip to content

Commit

Permalink
feat: type aliases (#1334)
Browse files Browse the repository at this point in the history
Closes #1308

### Summary of Changes

Add type aliases to simplify reuse of complex types:

```
typealias MyType = union<Int, String>
```
  • Loading branch information
lars-reimann authored Feb 26, 2025
1 parent 23896a4 commit 3d42bb0
Show file tree
Hide file tree
Showing 134 changed files with 1,252 additions and 96 deletions.
3 changes: 2 additions & 1 deletion docs/api/safeds/data/image/containers/Image.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pipeline example {

??? quote "Stub code in `Image.sdsstub`"

```sds linenums="14"
```sds linenums="13"
@Experimental
class Image {
/**
* Get the width of the image in pixels.
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/image/containers/ImageList.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ To create an `ImageList` call one of the following static methods:

??? quote "Stub code in `ImageList.sdsstub`"

```sds linenums="17"
```sds linenums="16"
@Experimental
class ImageList {
/**
* The number of images in this image list.
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/image/typing/ImageSize.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ A container for image size data.

??? quote "Stub code in `ImageSize.sdsstub`"

```sds linenums="15"
```sds linenums="14"
@Experimental
class ImageSize sub ConstantImageSize
```
{ data-search-exclude }
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/labeled/containers/ImageDataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pipeline example {

??? quote "Stub code in `ImageDataset.sdsstub`"

```sds linenums="25"
```sds linenums="24"
@Experimental
class ImageDataset<out O>(
@PythonName("input_data") inputData: ImageList,
@PythonName("output_data") outputData: O,
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/labeled/containers/TimeSeriesDataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pipeline example {

??? quote "Stub code in `TimeSeriesDataset.sdsstub`"

```sds linenums="29"
```sds linenums="28"
@Experimental
class TimeSeriesDataset(
data: union<Map<String, List<Any>>, Table>,
@PythonName("target_name") targetName: String,
Expand Down
7 changes: 4 additions & 3 deletions docs/api/safeds/data/tabular/containers/Column.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A named, one-dimensional collection of homogeneous values.
| Name | Type | Description | Default |
|------|------|-------------|---------|
| `name` | [`String`][safeds.lang.String] | The name of the column. | - |
| `data` | [`List<T>`][safeds.lang.List] | The data of the column. | `#!sds []` |
| `data` | [`List<T>`][safeds.lang.List] | The data of the column. | - |

**Type parameters:**

Expand All @@ -27,10 +27,11 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="19"
```sds linenums="18"
@Category(DataScienceCategory.BasicElement)
class Column<out T = Any?>(
name: String,
data: List<T> = []
data: List<T>,
) {
/**
* Whether the column is numeric.
Expand Down
4 changes: 2 additions & 2 deletions docs/api/safeds/data/tabular/containers/StringCell.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pipeline example {
* @example
* pipeline example {
* val column = Column("example", ["abc", "def", "ghi"]);
* val result = column.transform((cell) -> cell.str.substring(1, 2));
* val result = column.transform((cell) -> cell.str.substring(start = 1, length = 2));
* // Column("example", ["bc", "ef", "hi"])
* }
*/
Expand Down Expand Up @@ -559,7 +559,7 @@ Get a substring of the string value in the cell.
```sds hl_lines="3"
pipeline example {
val column = Column("example", ["abc", "def", "ghi"]);
val result = column.transform((cell) -> cell.str.substring(1, 2));
val result = column.transform((cell) -> cell.str.substring(start = 1, length = 2));
// Column("example", ["bc", "ef", "hi"])
}
```
Expand Down
7 changes: 4 additions & 3 deletions docs/api/safeds/data/tabular/containers/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To create a `Table` call the constructor or use one of the following static meth

| Name | Type | Description | Default |
|------|------|-------------|---------|
| `data` | [`Map<String, List<Any?>>?`][safeds.lang.Map] | The data of the table. If null, an empty table is created. | `#!sds null` |
| `data` | [`Map<String, List<Any?>>`][safeds.lang.Map] | The data of the table. If null, an empty table is created. | - |

**Examples:**

Expand All @@ -30,9 +30,10 @@ pipeline example {

??? quote "Stub code in `Table.sdsstub`"

```sds linenums="33"
```sds linenums="32"
@Category(DataScienceCategory.BasicElement)
class Table(
data: Map<String, List<Any?>>? = null
data: Map<String, List<Any?>>
) {
/**
* The names of the columns in the table.
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/tabular/containers/TemporalCell.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pipeline example {

??? quote "Stub code in `TemporalCell.sdsstub`"

```sds linenums="17"
```sds linenums="16"
@Experimental
class TemporalCell {
/**
* Get the century of the underlying date(time) data.
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/tabular/plotting/ColumnPlotter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pipeline example {

??? quote "Stub code in `ColumnPlotter.sdsstub`"

```sds linenums="17"
```sds linenums="16"
@Category(DataScienceCategory.BasicElement)
class ColumnPlotter(
column: Column<Any>
) {
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/data/tabular/plotting/TablePlotter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pipeline example {

??? quote "Stub code in `TablePlotter.sdsstub`"

```sds linenums="18"
```sds linenums="17"
@Category(DataScienceCategory.BasicElement)
class TablePlotter(
table: Table
) {
Expand Down
2 changes: 1 addition & 1 deletion docs/api/safeds/data/tabular/transformation/Discretizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The Discretizer bins continuous data into intervals.
```sds hl_lines="3"
pipeline example {
val table = Table({"a": [1, 2, 3, 4]});
val discretizer = Discretizer(2, columnNames = "a").fit(table);
val discretizer = Discretizer(binCount = 2, columnNames = "a").fit(table);
val transformedTable = discretizer.transform(table);
// Table({"a": [0, 0, 1, 1]})
}
Expand Down
9 changes: 9 additions & 0 deletions docs/api/safeds/lang/AnnotationTarget.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ The declaration types that can be targeted by annotations.
*/
Segment

/**
* The annotation can be called on type aliases.
*/
TypeAlias

/**
* The annotation can be called on type parameters.
*/
Expand Down Expand Up @@ -116,6 +121,10 @@ The annotation can be called on results.

The annotation can be called on segments.

## <code class="doc-symbol doc-symbol-variant"></code> `TypeAlias` {#safeds.lang.AnnotationTarget.TypeAlias data-toc-label='[variant] TypeAlias'}

The annotation can be called on type aliases.

## <code class="doc-symbol doc-symbol-variant"></code> `TypeParameter` {#safeds.lang.AnnotationTarget.TypeParameter data-toc-label='[variant] TypeParameter'}

The annotation can be called on type parameters.
9 changes: 8 additions & 1 deletion docs/api/safeds/lang/Category.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ The category of a declaration. It can be used for grouping.

??? quote "Stub code in `ideIntegration.sdsstub`"

```sds linenums="20"
```sds linenums="13"
@Experimental
@Targets([
AnnotationTarget.Class,
AnnotationTarget.Enum,
AnnotationTarget.Function,
AnnotationTarget.Segment,
])
annotation Category(category: DataScienceCategory)
```
{ data-search-exclude }
3 changes: 2 additions & 1 deletion docs/api/safeds/lang/DataScienceCategory.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ The letter "Q" is used as a separator for subcategories.

??? quote "Stub code in `ideIntegration.sdsstub`"

```sds linenums="27"
```sds linenums="26"
@Experimental
enum DataScienceCategory {
/**
* Basic building blocks.
Expand Down
13 changes: 12 additions & 1 deletion docs/api/safeds/lang/Deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ The declaration should no longer be used.

??? quote "Stub code in `maturity.sdsstub`"

```sds linenums="22"
```sds linenums="11"
@Targets([
AnnotationTarget.Annotation,
AnnotationTarget.Attribute,
AnnotationTarget.Class,
AnnotationTarget.Enum,
AnnotationTarget.EnumVariant,
AnnotationTarget.Function,
AnnotationTarget.Parameter,
AnnotationTarget.Result,
AnnotationTarget.Segment,
])
annotation Deprecated(
alternative: String? = null,
reason: String? = null,
Expand Down
13 changes: 12 additions & 1 deletion docs/api/safeds/lang/Experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ The declaration might change without a major version bump.

??? quote "Stub code in `maturity.sdsstub`"

```sds linenums="43"
```sds linenums="32"
@Targets([
AnnotationTarget.Annotation,
AnnotationTarget.Attribute,
AnnotationTarget.Class,
AnnotationTarget.Enum,
AnnotationTarget.EnumVariant,
AnnotationTarget.Function,
AnnotationTarget.Parameter,
AnnotationTarget.Result,
AnnotationTarget.Segment,
])
annotation Experimental
```
{ data-search-exclude }
4 changes: 3 additions & 1 deletion docs/api/safeds/lang/Expert.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ This parameter should only be used by expert users.

??? quote "Stub code in `ideIntegration.sdsstub`"

```sds linenums="8"
```sds linenums="6"
@Experimental
@Targets([AnnotationTarget.Parameter])
annotation Expert
```
{ data-search-exclude }
4 changes: 3 additions & 1 deletion docs/api/safeds/lang/Impure.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ The function has side effects and/or does not always return the same results giv

??? quote "Stub code in `purity.sdsstub`"

```sds linenums="23"
```sds linenums="21"
@Experimental
@Targets([AnnotationTarget.Function])
annotation Impure(allReasons: List<ImpurityReason>)
```
{ data-search-exclude }
8 changes: 4 additions & 4 deletions docs/api/safeds/lang/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pipeline example {
*
* @example
* pipeline example {
* val string = [1, 2, 3].join("-"); // "1-2-3"
* val string = [1, 2, 3].join(separator = "-"); // "1-2-3"
* }
*/
@Pure
Expand All @@ -53,7 +53,7 @@ pipeline example {
*
* @example
* pipeline example {
* val slice = [1, 2, 3].slice(1, 3); // [2, 3]
* val slice = [1, 2, 3].slice(start = 1, end = 3); // [2, 3]
* }
*/
@Pure
Expand Down Expand Up @@ -100,7 +100,7 @@ pipeline example {
```
```sds hl_lines="2"
pipeline example {
val string = [1, 2, 3].join("-"); // "1-2-3"
val string = [1, 2, 3].join(separator = "-"); // "1-2-3"
}
```

Expand Down Expand Up @@ -161,7 +161,7 @@ Return the slice of the list starting at the start index up to but excluding the

```sds hl_lines="2"
pipeline example {
val slice = [1, 2, 3].slice(1, 3); // [2, 3]
val slice = [1, 2, 3].slice(start = 1, end = 3); // [2, 3]
}
```

Expand Down
4 changes: 3 additions & 1 deletion docs/api/safeds/lang/Pure.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ reordering of calls or parallelization.

??? quote "Stub code in `purity.sdsstub`"

```sds linenums="12"
```sds linenums="10"
@Experimental
@Targets([AnnotationTarget.Function])
annotation Pure
```
{ data-search-exclude }
4 changes: 3 additions & 1 deletion docs/api/safeds/lang/PythonMacro.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ call. `$this` is replaced by the receiver of the call. `$param` is replaced by t

??? quote "Stub code in `codeGeneration.sdsstub`"

```sds linenums="12"
```sds linenums="10"
@Experimental
@Targets([AnnotationTarget.Function])
annotation PythonMacro(
template: String
)
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/lang/PythonModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ stubs.

??? quote "Stub code in `codeGeneration.sdsstub`"

```sds linenums="21"
```sds linenums="20"
@Targets([AnnotationTarget.Module])
annotation PythonModule(
qualifiedName: String
)
Expand Down
12 changes: 11 additions & 1 deletion docs/api/safeds/lang/PythonName.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ The name of the corresponding API element in Python. By default, this is the nam

??? quote "Stub code in `codeGeneration.sdsstub`"

```sds linenums="38"
```sds linenums="28"
@Targets([
AnnotationTarget.Attribute,
AnnotationTarget.Class,
AnnotationTarget.Enum,
AnnotationTarget.EnumVariant,
AnnotationTarget.Function,
AnnotationTarget.Parameter,
AnnotationTarget.Pipeline,
AnnotationTarget.Segment,
])
annotation PythonName(
name: String
)
Expand Down
3 changes: 2 additions & 1 deletion docs/api/safeds/lang/Repeatable.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ The annotation can be called multiple times for the same declaration.

??? quote "Stub code in `annotationUsage.sdsstub`"

```sds linenums="83"
```sds linenums="87"
@Targets([AnnotationTarget.Annotation])
annotation Repeatable
```
{ data-search-exclude }
4 changes: 2 additions & 2 deletions docs/api/safeds/lang/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pipeline example {
*
* @example
* pipeline example {
* val substring = "Hello, world!".substring(7, 12); // "world"
* val substring = "Hello, world!".substring(start = 7, end = 12); // "world"
* }
*/
@Pure
Expand Down Expand Up @@ -586,7 +586,7 @@ Return the substring of the string starting at the start index up to but excludi

```sds hl_lines="2"
pipeline example {
val substring = "Hello, world!".substring(7, 12); // "world"
val substring = "Hello, world!".substring(start = 7, end = 12); // "world"
}
```

Expand Down
11 changes: 10 additions & 1 deletion docs/api/safeds/lang/Tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ Tags to associate with a declaration. They can be used for filtering.

??? quote "Stub code in `ideIntegration.sdsstub`"

```sds linenums="94"
```sds linenums="85"
@Experimental
@Targets([
AnnotationTarget.Annotation,
AnnotationTarget.Class,
AnnotationTarget.Enum,
AnnotationTarget.Function,
AnnotationTarget.Pipeline,
AnnotationTarget.Segment,
])
annotation Tags(tags: List<String>)
```
{ data-search-exclude }
Loading

0 comments on commit 3d42bb0

Please sign in to comment.