-
Notifications
You must be signed in to change notification settings - Fork 10
/
Seekables.kt
72 lines (62 loc) · 1.74 KB
/
Seekables.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.snap.ui.seeking
/**
* Creators for common types of Seekables.
*/
object Seekables {
/**
* A seekable with zero items.
*/
@JvmStatic
fun <T> empty(): Seekable<T> {
return EmptySeekable
}
/**
* Creates an immutable Seekable from the given list.
*/
@JvmStatic
fun <T> copyOf(list: List<T>): Seekable<T> {
return ListSeekable(list.toList())
}
/**
* Creates a Seekable reversing a list.
*/
@JvmStatic
fun <T> reverse(list: List<T>): Seekable<T> {
return ReversingSeekable(copyOf(list))
}
/**
* Creates a Seekable reversing another Seekable.
*/
@JvmStatic
fun <T> reverse(source: Seekable<T>): Seekable<T> {
return ReversingSeekable(source)
}
/**
* Returns a Seekable of a single item.
*/
@JvmStatic
fun <T> of(item: T): Seekable<T> {
return ListSeekable(listOf(item))
}
@JvmStatic
fun <S, T> map(seekable: Seekable<S>, mapping: (s: S, position: Int) -> T): Seekable<T> {
return SeekableTransform(seekable, mapping)
}
@JvmStatic
fun <T> concat(head: Seekable<T>, tail: Seekable<T>): Seekable<T> {
return AppendedSeekable(head, tail)
}
@JvmStatic
fun <T> concat(seekables: List<Seekable<T>>): Seekable<T> {
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 <T> splice(content: Seekable<T>, splice: Seekable<T>, splicePosition: Int): Seekable<T> {
return SplicingSeekable(content, splice, splicePosition)
}
}