The D-day is coming for Golo and be sure to attend Julien’s talk at Devoxx !

In the meantime, here is a new piece of Golo.

module little.experiment2_1

import java.lang

function functionWithCase = |inputParameter| {
  case {
      when inputParameter == "This value" { println("this value spotted") }
      otherwise { println("otherwise was the answer") }
  }
}

function main = |args| {
  functionWithCase("This value")
  functionWithCase("not something to handle")
}

This illustrate the use of the Golo case word.
As you can see, the case expression is quite simple:
each when is based on a conditionnal expression that will allow the specified code to be executed.

It’s that simple !

But simple doesn’t mean powerless !
Golo allows you to write when conditions with several variables that may have different possible types.
Just look below:

module little.experiment2_2

import java.lang

function otherValue = { println("This value was numeric") }

function functionWithCase = |inputParameter, secondParameter| {
  case {
      when inputParameter == "This value" { println("this value spotted") }
      when secondParameter == "second" { println("second value") }
      when inputParameter == 42 { otherValue() }
      when (inputParameter == "first") and (secondParameter == "second too") { println("both") }
      otherwise { println("otherwise was the answer") }
  }
}

function main = |args| {
  functionWithCase("This value", "second")
  functionWithCase(42, "second")
  functionWithCase("not something to handle", "")
  functionWithCase("first", "second too")
}

That’s it for today folks !
Of course, feel free to contact me and ask question questions.
All comments are welcome here too.

See you when Golo is out ;)