Skip to content

Commit

Permalink
Add MutableProvider creation fun with only loadValue lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Aug 8, 2024
1 parent 28d9d0b commit 6fcbde0
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ fun <T> mutableProvider(initialValue: T): MutableProvider<T> =
override fun loadValue(): T = initialValue
}

/**
* Creates a new [MutableProvider] that loads its value using the given [loadValue] function.
*/
fun <T> mutableProvider(loadValue: () -> T): MutableProvider<T> =
object : AbstractProvider<T>() {
override fun loadValue(): T = loadValue()
}

/**
* Creates a new [MutableProvider] that loads its value using the given [loadValue] function
* and sets it using the given [setValue] function.
Expand Down

0 comments on commit 6fcbde0

Please sign in to comment.