Skip to content

Commit

Permalink
feat: Add LiveData map/switchmap extension functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pkeefe committed Nov 5, 2018
1 parent f2d6a07 commit 783fdf7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions library/src/main/java/com/perculacreative/ktx/LiveData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.perculacreative.ktx

import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations

fun <X, Y> LiveData<X>.map(mapFunction: (value: X?) -> Y): LiveData<Y> {
return Transformations.map(this, mapFunction)
}

fun <X, Y> LiveData<X>.switchMap(mapFunction: (value: X?) -> LiveData<Y>): LiveData<Y> {
return Transformations.switchMap(this, mapFunction)
}

0 comments on commit 783fdf7

Please sign in to comment.