score:9
First convert the method to a function, and then convert the function of two args into a function of one tuple.
Function.tupled(print _)(johnsmith)
score:10
In addition to Dave's answer, this works too:
(print _).tupled(johnsmith)
Usually, Function.tupled will work best for anonymous functions and closures in combination with map
and similar methods. For example:
List("abc", "def", "ghi").zipWithIndex.map(Function.tupled(_ * _))
In this case, the type for _ * _
is already defined by Function.tupled
. Try using tupled
for that instead and it won't work, because the function is defined before tupled
converts it.
For your particular case, tupled
works, since the type of print
is already known.
Source: stackoverflow.com
Related Query
- How can I call a function that takes 2 parameters with a Tuple2?
- convert a method call with parameters to a Function that takes no parameters
- How can I improve Scala's type inference with type parameters that don't show up in the first parameter list?
- How can I write a function that performs a case statement with a generic type?
- How to create a function that will only accept types that can be converted toJson with spray-json
- How to distinguish between a reference to a function with no paramters and a call to that function in Scala?
- How to declare a function with val in Scala that takes no Input
- How can I use an implicit function with two parameters (Scala)?
- How to call a function that has a Map with a Generic Type as a parameter
- How can I call Scala function with class name and function name as strings
- how can I write a function in scala called Order that takes one arguement: a list of Ints. And returns the same List of Ints from least to greatest
- Given any sized Seq[Any], how to call function with this where its parameters are different types, eg Int, String
- I have a function which takes an implicit parameter. How can I pass the parameter implicitly using implicit parameters of an instance of some class?
- How to call a scala function with parameters using java classloader?
- How can I dynamically invoke the same scala function in cascading manner with output of previous call goes as input to the next call
- Write a function that takes a function with specific parameters as parameter
- How can I call a Scala function taking a PartialFunction with a Unit return type from Java?
- Spark - Task not serializable: How to work with complex map closures that call outside classes/objects?
- Can extractors be customized with parameters in the body of a case statement (or anywhere else that an extractor would be used)?
- How do you create scala anonymous function with multiple implicit parameters
- How to reference a function that takes varargs
- scala coalesces multiple function call parameters into a Tuple -- can this be disabled?
- Scalaz: how can I accumulate Failures or apply a function to Validations with different types?
- How can I create an instance of a Case Class with constructor arguments with no Parameters in Scala?
- How to used named parameters with a curried function in scala
- How can you make custom function types in Scala with named parameters?
- How can I make multiple parameters in an anonymous function implicit?
- How can I combine shared tests with fixtures that require cleanup?
- How can I write a recursive polymorphic function with Shapeless
- (In Scala,) Is there anything that can be done with generic type parameters of classes but not with abstract type members?
More Query from same tag
- Is using Any for Union type a good idea?
- How to implement a JSON that contains a variable from another method in Scala?
- scala - get random Special Character (symbol)
- Getting the type of the default case in pattern maching
- Convert reduceByKey from Spark to Flink
- Spark scala running
- Scala Futures with DB
- Serialize/Broadcast large Map in Spark + Scala
- Spray Routing Doesn't match anything
- Compression in Scala
- What does the '<-' do in scala?
- diverging implicit expansion in implicit val GetResult
- Scala @elidable causes compiler to crash
- Convert scala FP-growth RDD output to Data frame
- Play! forms always has errors
- Why are implicit variables not initialized in Scala when called from unit test?
- Return Scala object to C++ using JNI
- How to use a specific row to modify the others in a dataframe
- Scala-Spark: Convert Dataframe to RDD[Edge]
- Replacing an Empty List with None When Working With Option[List[Long]]
- Spark-Scala HBase table creation fails (MetaException(message:file:/user/hive/warehouse/src is not a directory or unable to create one)
- Error: class file needed by ValidDateOrNumericTypeHolder, need RegisterJodaTimeConversionHelpers() - its hopeless, I can't find the import
- Spark - convert map to RDD
- How to test composition of futures inside a receive method of actor?
- How to read system variable into a conf file in Play framework
- sbt 0.13 task macro equivalent of flatMap
- Any work on Scala that is similar to WebSharper
- Scala: "Too many arguments" Error in IntelliJ IDEA 11 using Scala 2.7.7
- Scala library for finding plural of string, and possible singulars of a plural?
- com.typesafe.config.ConfigException$WrongType: system properties: path has type OBJECT rather than STRING