<commit_before>[//]: # (title: Functions)

Functions in Kotlin are declared using the `fun` keyword:

```kotlin
fun double(x: Int): Int {
    return 2 * x
}
```

## Function usage

Calling functions uses the traditional approach:

```kotlin
val result = double(2)
```

Calling member functions uses the dot notation:

```kotlin
Stream().read() // create instance of class Stream and call read()
```

### Parameters

Function parameters are defined using Pascal notation - *name*: *type*. Parameters are separated using commas. Each 
parameter must be explicitly typed:

```kotlin
fun powerOf(number: Int, exponent: Int): Int { /*...*/ }
```

You can use a [trailing comma](coding-conventions.md#trailing-commas) when you declare function parameters:

```kotlin
fun powerOf(
    number: Int,
    exponent: Int, // trailing comma
) { /*...*/ }
```

### Default arguments

Function parameters can have default values, which are used when you skip the corresponding argument. This reduces a number 
of overloads compared to other languages:

```kotlin
fun read(
    b: Array<Byte>, 
    off: Int = 0,
    len: Int = b.size,
) { /*...*/ }
```
<commit_msg>chore: change Array<Byte> to ByteArray (#2108)<commit_after>[//]: # (title: Functions)

Functions in Kotlin are declared using the `fun` keyword:

```kotlin
fun double(x: Int): Int {
    return 2 * x
}
```

## Function usage

Calling functions uses the traditional approach:

```kotlin
val result = double(2)
```

Calling member functions uses the dot notation:

```kotlin
Stream().read() // create instance of class Stream and call read()
```

### Parameters

Function parameters are defined using Pascal notation - *name*: *type*. Parameters are separated using commas. Each 
parameter must be explicitly typed:

```kotlin
fun powerOf(number: Int, exponent: Int): Int { /*...*/ }
```

You can use a [trailing comma](coding-conventions.md#trailing-commas) when you declare function parameters:

```kotlin
fun powerOf(
    number: Int,
    exponent: Int, // trailing comma
) { /*...*/ }
```

### Default arguments

Function parameters can have default values, which are used when you skip the corresponding argument. This reduces a number 
of overloads compared to other languages:

```kotlin
fun read(
    b: ByteArray, 
    off: Int = 0,
    len: Int = b.size,
) { /*...*/ }
```

{'fraction_non_alphanumeric': 0.1347061347061347, 'fraction_numerical': 0.00429000429000429, 'mean_word_length': 3.8583333333333334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6853266', 'n_tokens_mistral': 727, 'n_tokens_neox': 672, 'n_words': 275}