How can I define an anonymous generic Scala function?

Spread the love

Question Description

Let’s say I have this:

val myAnon:(Option[String],String)=>String = (a:Option[String],defVal:String) => {

Don’t mind what the function does. Is there anyway of making it generic, so I can have an Option[T]?

Practice As Follows

I don’t think anonymous functions can have type parameters. See this answer for details.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.