Groovy web console

subscribe to the feed Subscribe
to this
site

Elvis-vs-orElse

Published 4 months ago by Rafa
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def checkExpressions = { obj, otherObj ->
    def resultA = Optional.ofNullable(obj).orElse(otherObj)
    def resultB = obj ?: otherObj
    
    println "Para $obj -> A: $resultA | B: $resultB"
}
def checkExpressionsWithOther = checkExpressions.rcurry('other')
[ null, true, false ].each { checkExpressionsWithOther(it) }