Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pairwise #101

Closed
hoc081098 opened this issue Jul 6, 2022 · 0 comments · Fixed by #102
Closed

pairwise #101

hoc081098 opened this issue Jul 6, 2022 · 0 comments · Fixed by #102
Labels
enhancement New feature or request
Milestone

Comments

@hoc081098
Copy link
Owner

 fun <T> Flow<T>.pairwise(): Flow<Pair<T, T>> = flow {
  var last: Any? = null

  try {
    collect {
      if (last !== null) {
        emit(NULL_VALUE.unbox<T>(last) to it)
      }
      last = it ?: NULL_VALUE
    }
  } finally {
    last = null
  }
}
@hoc081098 hoc081098 added this to the 0.4.0 milestone Jul 6, 2022
@hoc081098 hoc081098 added the enhancement New feature or request label Jul 6, 2022
@hoc081098 hoc081098 linked a pull request Jul 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant