Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private val initializedModules = HashSet<Class<out ModuleInitializer>>()
fun getInitializerCompletable(): Completable {
val completableList = mutableListOf<Completable>()
map.forEach { (clazz, moduleInitializer) ->
completableList.addAll(getCompletableForModule(clazz, moduleInitializer))
}
return Completable.concat(completableList)
}
private fun getCompletableForModule(
clazz: Class<out ModuleInitializer>,
moduleToInitialize: ModuleInitializer
): List<Completable> {
if (moduleToInitialize.dependencies().isEmpty() && initializedModules.contains(clazz)) {
return emptyList()
} else {
val completableList = mutableListOf<Completable>()
moduleToInitialize.dependencies().forEach {
completableList.addAll(getCompletableForModule(it, map.getValue(it)))
}
if (!initializedModules.contains(clazz)) {
initializedModules.add(clazz)
completableList.add(moduleToInitialize.initialize(context))
}
return completableList
}
}
@stewemetal
Copy link

stewemetal commented Jun 21, 2020

map[it]!! could be replaced with map.getValue(it) if you want to avoid using !!. :) Also, you get a more detailed exception instead of an NPE this way.

@saurabharora90
Copy link
Author

saurabharora90 commented Jun 21, 2020

updated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment