Skip to content

Commit

Permalink
icerockdev#183 detekt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kramlex committed Sep 24, 2022
1 parent b698560 commit 753f0b0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("MaximumLineLength", "MaxLineLength")

package dev.icerock.moko.mvvm.flow

import dev.icerock.moko.mvvm.state.ResourceState
Expand All @@ -26,17 +28,17 @@ inline fun <TData, TError, reified ST : ResourceState<TData, TError>, FL : Flow<
list.firstOrNull { it !is ResourceState.Success<*, *> } == null
}

inline fun <TData, TError, reified ST : ResourceState<TData, TError>, LD : Flow<ST>> List<LD>.isLoadingState(): Flow<Boolean> =
inline fun <TData, TError, reified ST : ResourceState<TData, TError>, F : Flow<ST>> List<F>.isLoadingState(): Flow<Boolean> =
combine(this) { list ->
list.firstOrNull() { it is ResourceState.Loading<*, *> } != null
}

inline fun <TData, TError, reified ST : ResourceState<TData, TError>, LD : Flow<ST>> List<LD>.isErrorState(): Flow<Boolean> =
inline fun <TData, TError, reified ST : ResourceState<TData, TError>, F : Flow<ST>> List<F>.isErrorState(): Flow<Boolean> =
combine(this) { list ->
list.firstOrNull { it is ResourceState.Failed<*, *> } != null
}

inline fun <TData, TError, reified ST : ResourceState<TData, TError>, LD : Flow<ST>> List<LD>.isEmptyState(): Flow<Boolean> =
inline fun <TData, TError, reified ST : ResourceState<TData, TError>, F : Flow<ST>> List<F>.isEmptyState(): Flow<Boolean> =
combine(this) { list ->
list.firstOrNull { it is ResourceState.Empty<*, *> } != null
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ fun <IT, E, OT> Flow<ResourceState<IT, E>>.dataTransform(
transform: Flow<IT>.() -> Flow<OT>
): Flow<ResourceState<OT, E>> = flatMapLatest { state ->
when (state) {
is ResourceState.Success -> transform
.invoke(flowOf(state.data))
is ResourceState.Success -> transform(flowOf(state.data))
.map { ResourceState.Success(it) }
is ResourceState.Empty -> flowOf(ResourceState.Empty())
is ResourceState.Failed -> flowOf(ResourceState.Failed(state.error))
is ResourceState.Loading -> flowOf(ResourceState.Loading())
}

}

fun <T, IE, OE> Flow<ResourceState<T, IE>>.errorTransform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun <T, E> LiveData<ResourceState<T, E>>.isEmptyState(): LiveData<Boolean> =
fun <T, E, ST : ResourceState<T, E>, LD : LiveData<out ST>> List<LD>.isSuccessState(): LiveData<Boolean> =
MediatorLiveData(false)
.composition(this) { list ->
list.firstOrNull { it !is ResourceState.Success<*, *>} == null
list.firstOrNull { it !is ResourceState.Success<*, *> } == null
}

fun <T, E, ST : ResourceState<T, E>, LD : LiveData<out ST>> List<LD>.isLoadingState(): LiveData<Boolean> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class FlowTest {
assertEquals(
actual = mergeWithCounter,
expected = 4
) // FIXME: there's an extra mergeWith lambda call
)
assertEquals(expected = -11, actual = mapFlow.value.dataValue())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ open class LiveDataTest {
assertEquals(
actual = mergeWithCounter,
expected = 9
) // FIXME: there's an extra mergeWith lambda call
)
assertEquals(expected = -11, actual = mapLd.value.dataValue())
}

Expand Down

0 comments on commit 753f0b0

Please sign in to comment.