diff --git a/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/MappingSmartValue.kt b/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/MappingSmartValue.kt new file mode 100644 index 0000000..85084d1 --- /dev/null +++ b/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/MappingSmartValue.kt @@ -0,0 +1,12 @@ +package org.timemates.remote.value + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class MappingSmartValue( + source: SmartValue, + mapper: suspend (T?) -> R? +) : SmartValue { + override val localValue: Flow = source.localValue.map(mapper) + override val remoteValue: Flow = source.remoteValue.map(mapper) +} \ No newline at end of file diff --git a/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/SmartValue.kt b/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/SmartValue.kt index 3128a58..2e8297c 100644 --- a/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/SmartValue.kt +++ b/foundation/smart-value/src/commonMain/kotlin/org/timemates/remote/value/SmartValue.kt @@ -63,4 +63,8 @@ public interface SmartValue { ) } } +} + +public fun SmartValue.map(transform: suspend (T?) -> R?): SmartValue { + return MappingSmartValue(this, transform) } \ No newline at end of file