Last active
March 28, 2024 00:19
-
-
Save osipxd/638cc9f3b6a483177d2e9bb7c8697ca4 to your computer and use it in GitHub Desktop.
Transparent wrapper making lists Immutable for compose.
This file contains hidden or 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
/** Wrapper over the given [list] for Compose to mark this list as [Immutable]. */ | |
@Immutable | |
@JvmInline | |
value class ImmutableList<T>(private val list: List<T>) : List<T> by list | |
/** Returns empty list marked as [Immutable]. */ | |
inline fun <T> immutableListOf(): ImmutableList<T> = ImmutableList(emptyList()) | |
/** Returns a new [Immutable] list of given [elements]. */ | |
inline fun <T> immutableListOf(vararg elements: T): ImmutableList<T> = ImmutableList(elements.asList()) | |
/** Wraps [this] list with [ImmutableList] so Compose considers it [Immutable]. */ | |
inline fun <T> List<T>.asImmutableList(): ImmutableList<T> = ImmutableList(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment