Skip to content

Commit

Permalink
chore(publish): prepare for v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed May 11, 2024
1 parent 6732002 commit f75fc61
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# Change Log

## [Unreleased] - TBD
## [0.8.1] - TBD

### Fixed
### Changed

- Update dependencies:
- [Kotlin `1.9.24`](https://github.com/JetBrains/kotlin/releases/tag/v1.9.24).
- [KotlinX Coroutines `1.8.1`](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.8.1).
- `Gradle` to `8.7`.

### Added

- Add `Flow.catchAndReturn`, `Flow.catchAndResume` operators.
- Add `Flow.mapToResult`, `Flow.mapResultCatching`, `Flow.throwFailure` operators.

### Changed

- `Flow.chunked(bufferSize: Int)` / `Flow.bufferCount(bufferSize: Int)`: reduce unnecessary allocations.

##### Changelog relative to version [0.8.1-Beta]

- `Flow.mapResultCatching` now does not catch `CancellationException`
thrown from the `transform` lambda.

- [Kotlin `1.9.24`](https://github.com/JetBrains/kotlin/releases/tag/v1.9.24).

## [0.8.1-Beta] - Mar 23, 2024

### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[![Build](https://github.com/hoc081098/FlowExt/actions/workflows/build.yml/badge.svg)](https://github.com/hoc081098/FlowExt/actions/workflows/build.yml)
[![Validate Gradle Wrapper](https://github.com/hoc081098/FlowExt/actions/workflows/gradle-wrapper-validation.yml/badge.svg)](https://github.com/hoc081098/FlowExt/actions/workflows/gradle-wrapper-validation.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Kotlin version](https://img.shields.io/badge/Kotlin-1.9.22-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
[![KotlinX Coroutines version](https://img.shields.io/badge/Kotlinx_Coroutines-1.8.0-blueviolet?logo=kotlin&logoColor=white)](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.8.0)
[![Kotlin version](https://img.shields.io/badge/Kotlin-1.9.24-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
[![KotlinX Coroutines version](https://img.shields.io/badge/Kotlinx_Coroutines-1.8.1-blueviolet?logo=kotlin&logoColor=white)](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.8.1)
![badge][badge-android]
![badge][badge-wearos]
![badge][badge-android-native]
Expand Down
15 changes: 7 additions & 8 deletions src/commonMain/kotlin/com/hoc081098/flowext/bufferCount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,19 @@ private fun <T> Flow<T>.bufferSkip(bufferSize: Int, skip: Int): Flow<List<T>> {

private fun <T> Flow<T>.bufferExact(bufferSize: Int): Flow<List<T>> {
return flow {
var buffer: MutableList<T> = mutableListOf()
var buffer: MutableList<T>? = null

collect { element ->
buffer += element
val b = buffer ?: mutableListOf<T>().also { buffer = it }
b += element

if (buffer.size >= bufferSize) {
emit(buffer)
buffer = mutableListOf()
if (b.size >= bufferSize) {
emit(b)
buffer = null
}
}

// Emits remaining buffer
if (buffer.isNotEmpty()) {
emit(buffer)
}
buffer?.let { emit(it) }
}
}
25 changes: 25 additions & 0 deletions src/commonTest/kotlin/com/hoc081098/flowext/BufferCountTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ class BufferCountTest : BaseTest() {
Event.Complete,
),
)

range(0, 10)
.bufferCount(1)
.test((0..9).map { Event.Value(listOf(it)) } + Event.Complete)

range(0, 10)
.bufferCount(3)
.test(
listOf(
Event.Value(listOf(0, 1, 2)),
Event.Value(listOf(3, 4, 5)),
Event.Value(listOf(6, 7, 8)),
Event.Value(listOf(9)),
Event.Complete,
),
)

range(0, 10)
.bufferCount(11)
.test(
listOf(
Event.Value((0..9).toList()),
Event.Complete,
),
)
}

@Test
Expand Down

0 comments on commit f75fc61

Please sign in to comment.