Hi if someone more experienced with kotlinx Flow c...
# android
f
Hi if someone more experienced with kotlinx Flow courotines could help I would appreciate, I want to modify the following code
Copy code
@HiltViewModel
class FeedViewModel @Inject constructor(
    savedStateHandle: SavedStateHandle,
    private val feedRepository: FeedRepository,
    private val profileRepository: ProfileRepository,
    private val activeAccountStore: ActiveAccountStore,
) : ViewModel() {

    private val feedDirective: String = savedStateHandle.feedDirective ?: "network;trending"

    private val _state = MutableStateFlow(
        UiState(
            posts = feedRepository.feedByDirective(feedDirective = feedDirective)
                .map { it.map { feed -> feed.asFeedPostUi() } }
                .cachedIn(viewModelScope),
        )
    )
 (...)
assuming feedRepository.feedByDirective returns Flow<PagingData<FeedPost>> and I want to use
Copy code
fun loadProfile(profileId: String): Flow<Profile>
from profileRepository
to load several Profile by the profileIds which are included in FeedPost fields, and somehow concat them into the flow
And having each post with its profiles loaded so that asFeedPostUi can use them on the UI
v
Copy code
val uiState: StateFlow<UiState> = repo.getData()
    .map { data ->
        UiState(data.someFileds)
    }
    .stateIn(
        scope = viewModelScope,
        started = WhileUiSubscribed,
        initialValue = UiState()
    )
There are plenty of the examples. https://github.com/android/architecture-samples/blob/main/app/src/main/java/com/ex[…]chitecture/blueprints/todoapp/taskdetail/TaskDetailViewModel.kt