package com.snap.ui.seeking /** * Creators for common types of Seekables. */ object Seekables { /** * A seekable with zero items. */ @JvmStatic fun empty(): Seekable { return EmptySeekable } /** * Creates an immutable Seekable from the given list. */ @JvmStatic fun copyOf(list: List): Seekable { return ListSeekable(list.toList()) } /** * Creates a Seekable reversing a list. */ @JvmStatic fun reverse(list: List): Seekable { return ReversingSeekable(copyOf(list)) } /** * Creates a Seekable reversing another Seekable. */ @JvmStatic fun reverse(source: Seekable): Seekable { return ReversingSeekable(source) } /** * Returns a Seekable of a single item. */ @JvmStatic fun of(item: T): Seekable { return ListSeekable(listOf(item)) } @JvmStatic fun map(seekable: Seekable, mapping: (s: S, position: Int) -> T): Seekable { return SeekableTransform(seekable, mapping) } @JvmStatic fun concat(head: Seekable, tail: Seekable): Seekable { return AppendedSeekable(head, tail) } @JvmStatic fun concat(seekables: List>): Seekable { return ConcatSeekable(seekables) } /** * Returns a [Seekable] that splices another Seekable at the given position. * If `spliceAt` is beyond the length of `content`, then `splice` * is appended to the end of `content`. */ @JvmStatic fun splice(content: Seekable, splice: Seekable, splicePosition: Int): Seekable { return SplicingSeekable(content, splice, splicePosition) } }