Skip to content

Instantly share code, notes, and snippets.

@Nillerr
Last active January 13, 2024 20:13
Show Gist options
  • Save Nillerr/920f10a35da225cca7a04c06fcf73a44 to your computer and use it in GitHub Desktop.
Save Nillerr/920f10a35da225cca7a04c06fcf73a44 to your computer and use it in GitHub Desktop.

Flow Wrapper Function (Live Templates)

flow wrap

Creates a wrapper for a function returning Flow accepting no arguments

fun $NAME$(onEach: ($TYPE$) -> Unit, onCompletion: (Throwable?) -> Unit): Cancellable =
    $NAME$().collect(onEach, onCompletion)

flow wrap 1

Creates a wrapper for a function returning Flow accepting one argument

fun $NAME$($P1$: $T1$, onEach: ($TYPE$) -> Unit, onCompletion: (Throwable?) -> Unit): Cancellable =
    $NAME$($P1$).collect(onEach, onCompletion)

You can extend this pattern to any number of arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment