Coverage Summary for Class: GetCharactersImpl (com.javiersc.samples.strategies.characters)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
GetCharactersImpl |
0%
(0/2)
|
|
0%
(0/8)
|
0%
(0/20)
|
GetCharactersImpl$invoke$$inlined$map$1 |
|
GetCharactersImpl$invoke$$inlined$map$1$2 |
|
GetCharactersImpl$invoke$$inlined$map$1$2$1 |
|
Total |
0%
(0/2)
|
|
0%
(0/8)
|
0%
(0/20)
|
package com.javiersc.samples.strategies.characters
import app.cash.sqldelight.coroutines.asFlow
import app.cash.sqldelight.coroutines.mapToList
import com.javiersc.kaari.samples.strategies.internal.CharacterEntity
import com.javiersc.kaari.samples.strategies.internal.KaariDatabase
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
interface GetCharacters {
operator fun invoke(): Flow<List<Character>>
}
class GetCharactersImpl(
private val coroutineContext: CoroutineContext,
private val database: KaariDatabase,
) : GetCharacters {
override fun invoke(): Flow<List<Character>> =
database.characterQueries
.selectAll()
.asFlow()
.mapToList(coroutineContext)
.map(List<CharacterEntity>::toCharacters)
}
private fun List<CharacterEntity>.toCharacters(): List<Character> =
map(CharacterEntity::toCharacter)
private fun CharacterEntity.toCharacter(): Character = Character(id, name)