2. BENVOLIO
Why, what is Tybalt?
MERCUTIO
More than Prince of Cats. Oh, he’s the courageous
captain of compliments. He fights as you sing prick-song,
keeps time, distance, and proportion. He rests his minim
rests—one, two, and the third in your bosom. The very
butcher of a silk button, a duelist, a duelist, a gentleman of
the very first house of the first and second cause. Ah, the
immortal passado, the punto reverso, the hai!
7. There is no perfect tool or method
What works in one context is suicidal in others
Special purpose tools only suit special circumstances
We never want to ‘fight in remiss’
Lessons Learned
13. Java is a legacy language!
But in Java 11…
Kotlin has it today!!
Scala had it
years ago!!
No one gives
a **** about
modules!!
14. fun main(args: Array<String>) {
val numbers = mutableListOf<Int>()
val scanner = Scanner(System.`in`)
val endOfInput = Regex("X{3}")
println("Enter some numbers or three 'X' to finish")
while (scanner.hasNextLine()) {
if (scanner.hasNext(endOfInput.toPattern())) {
break
} else if (scanner.hasNextInt()) {
numbers += scanner.nextInt()
} else {
val mysteryText = scanner.nextLine()
println("Ignoring $mysteryText")
}
}
//Would be better to use ‘numbers.sum()’
val total = numbers.fold(0, Int::plus)
println("Total of numbers is: $total")
}
A Simple Kotlin Example
Points to note:
No redundant class
No semi-colons
Type inference
Both ‘val’ and ‘var’
Helper functions
String interpolation
Simplified collections
Interop with Java types
Simpler use of FP
24. fun printPostcode(person: Person) {
val result = Option.monad().binding {
val address = person.residence().bind()
val location = address.location().bind()
location.value().bind()
}.fix()
println(result.fold( { "No postcode available" },
{ "Postcode of $it" }))
}
Using Option as a Monad in Arrow and Scala
def printPostcode(person: Person) {
for (
place <- person residence;
code <- place location;
result <- code value
) println(result)
}