I'm pretty new to scala and still in the early days of learning. I was reading an article that had an example like so:
def example(_list: List[Positions], function: Position => Option[Path]): Option[Path] = _list match {...}
NB
- Position is a
(Int,Int) - Path is a
List( Position )
From what I understand, this method will hold:
list of positionsOption[Path]
and will return Option[Path]
What I don't understand is how are we supposed to call this method?
I tried this:
example(Nil, Option( 0,0 ) )
The type of
functionisPosition => Option[Path]- this is not a by-name argument, it's a type that is equivalent toFunction1[Position, Option[Path]]- a function that takes one argument of typePositionand returns anOption[Path].So, when you call it you can pass an anonymous function with matching type, e.g.:
You can also pass a method with matching type, e.g.: