Add a few source helper functions

This commit is contained in:
Jobobby04
2021-07-25 14:16:16 -04:00
parent 81af5a5654
commit e40fbbecbb
9 changed files with 34 additions and 21 deletions
@@ -107,6 +107,13 @@ fun Source.getMainSource(): Source = if (this is EnhancedHttpSource) {
this
}
@JvmName("getMainSourceInline")
inline fun <reified T : Source> Source.getMainSource(): T? = if (this is EnhancedHttpSource) {
this.source() as? T
} else {
this as? T
}
fun Source.getOriginalSource(): Source = if (this is EnhancedHttpSource) {
this.originalSource
} else {
@@ -118,3 +125,11 @@ fun Source.getEnhancedSource(): Source = if (this is EnhancedHttpSource) {
} else {
this
}
inline fun <reified T> Source.anyIs(): Boolean {
return if (this is EnhancedHttpSource) {
originalSource is T || enhancedSource is T
} else {
this is T
}
}