Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created May 29, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1monw1/5f167f1517ab6a55cef1b44def9dba73 to your computer and use it in GitHub Desktop.
Save s1monw1/5f167f1517ab6a55cef1b44def9dba73 to your computer and use it in GitHub Desktop.
data class PageableDTO(val offset: Int, val limit: Int, val sortBy: String? = null, val ascending: Boolean? = null)
fun PageableDTO.injectDefaults() =
copy(sortBy = if (sortBy?.isNotEmpty() == true) sortBy else "created_ts", ascending = ascending ?: true)
fun main(args: Array<String>) {
val pageableDTO = PageableDTO(1, 2)
val withDefaults = pageableDTO.injectDefaults()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment