Created
February 5, 2022 19:05
-
-
Save DevSrSouza/7dee00bfb2c88e4143f95afcaae997b5 to your computer and use it in GitHub Desktop.
InsertSectionHeader Paging 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public inline fun <reified T : R, R : Any, C : Any> PagingData<T>.insertSectionHeader( | |
crossinline sectionBy: suspend (T) -> C, | |
crossinline insert: suspend (T) -> R, | |
): PagingData<R> { | |
return insertSeparators { first: T?, second: T? -> | |
if(first == null && second != null) | |
return@insertSeparators insert(second) | |
if(second == null) return@insertSeparators null | |
if(first !is T) return@insertSeparators null | |
val firstSectionByValue = sectionBy(first) | |
val secondSectionByValue = sectionBy(second) | |
if(firstSectionByValue != secondSectionByValue) { | |
insert(first) | |
} else { | |
null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment