Created
May 6, 2022 12:11
-
-
Save alana-mullen/c6712967fd6c8066618b08f3545b0c3a to your computer and use it in GitHub Desktop.
Kotlin extension to return the first and last items from a List
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
/** | |
* Return the first and last items from a List | |
*/ | |
fun <T> List<T>.ends(): List<T> { | |
if (this.size > 1) return this.take(1) + this.takeLast(1) | |
return this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment