println("Hello :)")
println(list[1,2,3]:get(2))
let l = list[1,2,"3"]
let s = set["lions","tigers","bears"] # you can use let
println(s) #[lions, tigers, bears]
s:add("Honey badger")
#s = s + "Honey badger" -> cast to String
println(s)
s:remove("lions")
println(s)
let m = map[
["firstName", "Bob"]
, ["lastName", "Morane"]
]
println(
m:get("firstName") + " " + m:get("lastName")
)
let hobbits = list["frodo","samwise","pippin"]
hobbits:each(|hobbit|->println(hobbit))
println(hobbits:head())
println(hobbits:tail())
println(hobbits:getLast())
println(
hobbits:filter(|hobbit|-> hobbit:length() is 5)
)
println(
hobbits:map(|hobbit|-> hobbit:length())
)
let x = 5
println(match {
when x is 1 then "one"
when x is 2 then "two"
when x > 2 and x < 4 then "more than 2, less than 4"
otherwise "many"
})
# see this : http://golo-lang.org/documentation/next/#_why_no_value_from_most_control_flow_constructions
let x = 2
println(match {
when x is 1 or x is 2 then "one or two"
when x is 3 then "three"
otherwise "other values"
})
let y = "pouet"
println(match {
when y oftype Integer.class then "integer: " + y
when y oftype Double.class then "a double"
when y oftype String.class then "I want to say " + y
otherwise "Mais euh ..."
})
# en attendant
let item = "foo@bar.com"
let what_it_could_be = -> match {
when item: contains("@") then "an email?"
when item: startsWith("+33") then "a French phone number?"
when item: startsWith("http://") then "a website URL?"
otherwise "I have no clue, mate!"
}
# prints "an email?"
println(what_it_could_be(item))