Is it possible to create a partially applied function with a named parameter?

This feature is provided.

def foo( a: String = "bar", b: Int = 1, c: String = "default" ): String 

Is there a way to create a partial function String => String without specifying a and b ? My foo( c = _: String ) approach, unfortunately, does not compile. Are there any alternatives?

+4
source share
1 answer

As Travis noted, this works:

 def foo( a: String = "bar", b: Int = 1, c: String = "default" ): String = s"$a$b$c" val fooc = (c: String) => foo(c = c) fooc("myc") //> res0: String = bar1myc 
+3
source

Source: https://habr.com/ru/post/1498724/


All Articles