Skip to content

Instantly share code, notes, and snippets.

@alana-mullen
Created May 6, 2022 12:11
Show Gist options
  • Save alana-mullen/c6712967fd6c8066618b08f3545b0c3a to your computer and use it in GitHub Desktop.
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
/**
* 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