Skip to content

Commit

Permalink
feat: SmartValue<T>.map function (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
y9vad9 authored Mar 24, 2024
1 parent e61ea52 commit 806b99a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.timemates.remote.value

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

internal class MappingSmartValue<T, R>(
source: SmartValue<T>,
mapper: suspend (T?) -> R?
) : SmartValue<R> {
override val localValue: Flow<R?> = source.localValue.map(mapper)
override val remoteValue: Flow<R?> = source.remoteValue.map(mapper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public interface SmartValue<T> {
)
}
}
}

public fun <T, R> SmartValue<T>.map(transform: suspend (T?) -> R?): SmartValue<R> {
return MappingSmartValue(this, transform)
}

0 comments on commit 806b99a

Please sign in to comment.