or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.md

index.mddocs/

0

# Kotlin Standard Library JRE 8 Extension

1

2

The Kotlin Standard Library JRE 8 Extension provides enhanced integration with Java 8 specific features. This package offers bidirectional conversion between Kotlin sequences and Java 8 streams, regex enhancements with named group support, and collection utilities optimized for JRE 8.

3

4

**Note**: This package is deprecated in favor of `kotlin-stdlib-jdk8` which provides the same functionality with updated naming conventions.

5

6

## Package Information

7

8

- **Package Name**: kotlin-stdlib-jre8

9

- **Package Type**: maven

10

- **Language**: Kotlin

11

- **Installation**: `implementation 'org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.71'`

12

13

## Core Imports

14

15

```kotlin

16

import kotlin.streams.*

17

import kotlin.text.*

18

```

19

20

## Basic Usage

21

22

```kotlin

23

import kotlin.streams.*

24

import java.util.stream.Stream

25

26

// Convert Java 8 Stream to Kotlin Sequence

27

val stream = Stream.of("apple", "banana", "cherry")

28

val sequence = stream.asSequence()

29

30

// Convert Kotlin Sequence back to Java 8 Stream

31

val backToStream = sequence.asStream()

32

33

// Collect stream directly to List

34

val list = Stream.of(1, 2, 3, 4, 5).toList()

35

println(list) // [1, 2, 3, 4, 5]

36

```

37

38

## Capabilities

39

40

### Stream to Sequence Conversion

41

42

Convert Java 8 Stream types to Kotlin Sequences for functional programming integration.

43

44

```kotlin { .api }

45

/**

46

* Creates a Sequence instance that wraps the original stream iterating through its elements

47

*/

48

fun <T> Stream<T>.asSequence(): Sequence<T>

49

50

/**

51

* Creates a Sequence instance that wraps the original IntStream iterating through its elements

52

*/

53

fun IntStream.asSequence(): Sequence<Int>

54

55

/**

56

* Creates a Sequence instance that wraps the original LongStream iterating through its elements

57

*/

58

fun LongStream.asSequence(): Sequence<Long>

59

60

/**

61

* Creates a Sequence instance that wraps the original DoubleStream iterating through its elements

62

*/

63

fun DoubleStream.asSequence(): Sequence<Double>

64

```

65

66

### Sequence to Stream Conversion

67

68

Convert Kotlin Sequences to Java 8 Streams for interoperability with Java APIs.

69

70

```kotlin { .api }

71

/**

72

* Creates a sequential Stream instance that produces elements from the original sequence

73

*/

74

fun <T> Sequence<T>.asStream(): Stream<T>

75

```

76

77

### Stream to List Collection

78

79

Collect Java 8 Stream elements directly to Kotlin Lists.

80

81

```kotlin { .api }

82

/**

83

* Returns a List containing all elements produced by this stream

84

*/

85

fun <T> Stream<T>.toList(): List<T>

86

87

/**

88

* Returns a List containing all elements produced by this IntStream

89

*/

90

fun IntStream.toList(): List<Int>

91

92

/**

93

* Returns a List containing all elements produced by this LongStream

94

*/

95

fun LongStream.toList(): List<Long>

96

97

/**

98

* Returns a List containing all elements produced by this DoubleStream

99

*/

100

fun DoubleStream.toList(): List<Double>

101

```

102

103

**Usage Examples:**

104

105

```kotlin

106

import kotlin.streams.*

107

import java.util.stream.Stream

108

import java.util.stream.IntStream

109

110

// Stream to Sequence conversion

111

val stream = Stream.of("hello", "world", "kotlin")

112

val sequence = stream.asSequence()

113

val uppercased = sequence.map { it.uppercase() }.toList()

114

115

// IntStream to List

116

val numbers = IntStream.range(1, 6).toList() // [1, 2, 3, 4, 5]

117

118

// Sequence to Stream

119

val kotlinSequence = sequenceOf(1, 2, 3, 4, 5)

120

val javaStream = kotlinSequence.asStream()

121

val sum = javaStream.mapToInt { it }.sum()

122

```

123

124

### Regex Named Groups

125

126

Enhanced regex functionality with named capture group support.

127

128

```kotlin { .api }

129

/**

130

* Returns a named group with the specified name

131

* @param name The name of the capture group

132

* @return An instance of MatchGroup if the group was matched, null otherwise

133

* @throws UnsupportedOperationException if getting named groups isn't supported on the current platform

134

*/

135

operator fun MatchGroupCollection.get(name: String): MatchGroup?

136

```

137

138

**Usage Examples:**

139

140

```kotlin

141

import kotlin.text.*

142

143

val regex = "(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})".toRegex()

144

val matchResult = regex.find("2023-12-25")

145

if (matchResult != null) {

146

val year = matchResult.groups["year"]?.value // "2023"

147

val month = matchResult.groups["month"]?.value // "12"

148

val day = matchResult.groups["day"]?.value // "25"

149

}

150

```

151

152

153

## Types

154

155

All functions use standard Kotlin and Java types:

156

157

```kotlin { .api }

158

// Java 8 Stream types

159

java.util.stream.Stream<T>

160

java.util.stream.IntStream

161

java.util.stream.LongStream

162

java.util.stream.DoubleStream

163

164

// Kotlin types

165

kotlin.sequences.Sequence<T>

166

kotlin.collections.List<T>

167

kotlin.text.MatchGroup

168

kotlin.text.MatchGroupCollection

169

```

170

171

## Version Compatibility

172

173

- **Kotlin Version**: 1.2.71

174

- **Java Version**: JRE/JDK 8+

175

- **Since**: Kotlin 1.1 (all public functions annotated with `@SinceKotlin("1.1")`)

176

177

## Migration Notice

178

179

This package is deprecated. For new projects or when updating dependencies, use `kotlin-stdlib-jdk8` instead:

180

181

```kotlin

182

// Old (deprecated)

183

implementation 'org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.71'

184

185

// New (recommended)

186

implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71'

187

```

188

189

The API remains the same between both packages.