Merge pull request #9546 from alimate/BAEL-4309

BAEL-4309: Invoke Operator Function
This commit is contained in:
Eric Martin 2020-06-26 19:31:56 -05:00 committed by GitHub
commit b28a4dac7e
2 changed files with 6 additions and 0 deletions

View File

@ -6,6 +6,7 @@ interface Page<T> {
fun elements(): MutableList<T>
}
operator fun <T> Page<T>.invoke(index: Int): T = elements()[index]
operator fun <T> Page<T>.get(index: Int): T = elements()[index]
operator fun <T> Page<T>.get(start: Int, endExclusive: Int): List<T> = elements().subList(start, endExclusive)
operator fun <T> Page<T>.set(index: Int, value: T) {

View File

@ -14,6 +14,11 @@ class PageTest {
assertEquals(page[1, 3], listOf("Kotlin", "Scala"))
}
@Test
fun `Invoke convention should work as expected`() {
assertEquals(page(1), "Kotlin")
}
@Test
fun `In convention should work on a page as expected`() {
assertTrue("Kotlin" in page)