From 6fcbde009942482d4a1138d4049e407caf27e784 Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:25:43 +0200 Subject: [PATCH] Add MutableProvider creation fun with only loadValue lambda --- .../xenondevs/commons/provider/mutable/BasicProviders.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/commons-provider/src/main/kotlin/xyz/xenondevs/commons/provider/mutable/BasicProviders.kt b/commons-provider/src/main/kotlin/xyz/xenondevs/commons/provider/mutable/BasicProviders.kt index 821252b..1f0ee17 100644 --- a/commons-provider/src/main/kotlin/xyz/xenondevs/commons/provider/mutable/BasicProviders.kt +++ b/commons-provider/src/main/kotlin/xyz/xenondevs/commons/provider/mutable/BasicProviders.kt @@ -11,6 +11,14 @@ fun mutableProvider(initialValue: T): MutableProvider = override fun loadValue(): T = initialValue } +/** + * Creates a new [MutableProvider] that loads its value using the given [loadValue] function. + */ +fun mutableProvider(loadValue: () -> T): MutableProvider = + object : AbstractProvider() { + 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.