Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Created October 17, 2017 01:03
Show Gist options
  • Save bohdanszymanik/2519a0b068ce1a4d82eff28f768db593 to your computer and use it in GitHub Desktop.
Save bohdanszymanik/2519a0b068ce1a4d82eff28f768db593 to your computer and use it in GitHub Desktop.
// no pattern matching but there are when clauses that return values
fun int2Bool (i:Int): Boolean =
when (i) {
0 -> false
else -> true
}
fun bool2Int (b:Boolean): Int = // so you can put functions before or after use - not order dependent
when (b) {
true -> 1
else -> 0
}
//functions can appear before or after use
// date handling - use the java.time classes preferentially
fun dateParse(d:java.sql.Date?) =
if (d != null) {
"'" + (d.toLocalDate()).format(java.time.format.DateTimeFormatter.ISO_DATE) + "'"
// "'" + (d.toLocalDate()).format(java.time.format.DateTimeFormatter.ofPattern("d MMM yyyy")) + "'"
} else { "null" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment