I'm looking at this sample code and after entering it in the scala repl I can see how it works.
val twice: Int => Int =
x => x * 2
This is similar:
val parse: String => Option[Int] =
s => if(s.matches("-?[0-9]+")) Some(s.toInt) else None
Can someone please deconstruct the above method and explain how this works?
I can see the name twice or parse, followed by the type which is Int => Int or String => Option[Int].
Now in the 2nd line of both functions you have a variable x or s. I can only assume this is the parameter.
Also if you can expand on what scala features allow a function to be written like this.
Thanks!