Created
October 17, 2017 01:03
-
-
Save bohdanszymanik/2519a0b068ce1a4d82eff28f768db593 to your computer and use it in GitHub Desktop.
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
// 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