Add a few source helper functions
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user