score:6
Accepted answer
it's not about the codomain, it's the wrong function arity.the method map
expects a function with a single argument, even if this argument is a tuple:
((int, int)) => (int, int) // function[(int, int), (int, int)]
but you are passing it a function that takes two arguments (two ints):
(int, int) => (int, int) // function2[int, int, (int, int)]
do either this:
def fun1(t: (int, int)) = (t._1+1, t._2)
l map fun1
or this:
def fun1(t1: int,t2: int) = (t1+1,t2)
l map { case (x, y) => fun1(x, y) }
here is a similar example with a more detailed explanation for a similar issue.
score:3
you have to use case
to destruct the tuple.
val l = list((1,2),(2,3),(3,4))
def fun1(t1: int,t2: int) = (t1+1,t2)
l map { case (a, b) => fun1(a, b) }
but, if you declare your function like below to make it work
def fun1(t: (int, int)) = (t._1 + 1,t._2)
l map fun1
Source: stackoverflow.com
Related Query
- Map needs not inferred codomain in Scala?
- Nice way to add number to element in Scala map if key exists or insert new element it not
- scala annotation argument needs to be constant but final val does not make it
- scala Duration: "This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent."
- Scala map on iterator does not produce side effects
- why scala Map does not implement unapply?
- scala - why map.size return 0 when the map is not empty
- Scala Option type not inferred as expected
- Scala type bounds not inferred correctly in match statement
- Scala sorted map does not have methods floor or ceil
- Scala map example not working as expected
- How to use mutable map in Scala on Apache Spark? Key not found error
- Scala filter a sequence to map with elements that respect and not respect filter condition
- scala map in a method argument can not add key-value
- Scala map method not behaving as expected
- Why is this Spring map not injecting into my Scala object?
- Map containing Objects not working as expected Scala
- Scala - Inner map returns value ( not an option of that value )
- Why map function in scala not reading Arrays
- scala underscore parameter not acting as named parameter, in spark map reduce
- Why does the creation of a map in scala not need and allow the new operator?
- Not able to parse Map with Enum to Json in Play Scala
- Scala - error "value map is not a member of"
- Scala error "value map is not a member of Double"
- scala map method can not correctly resolve function type in collection with fixed function types
- Control not reaching to Specific Location in Scala Nested Map
- Scala Play framework Forms, type not automatically inferred for a tuple parameter
- map on a TreeMap returns a Map and not a TreeMap in Scala
- Map variables not usable in Scala Play HTML template
- scala - create a mutable map and with default value as (0,0) if key not exist
More Query from same tag
- Simple scala playframework app doesn't work on heroku
- Spark fails on big shuffle jobs with java.io.IOException: Filesystem closed
- Tail recursion with List + .toVector or Vector?
- Create hive Views using scala /spark
- How to map in Slick MySQL TINYINT(1) column?
- maven and lift using scala 2.8 : lift-mapper missing?
- How to define custom equality in case classes
- How do I define mappers in Scala for a Cassandra sink in Flink?
- spray-can simple-http-server example how are Bound messages handled?
- How do I change Guice bindings for functional tests?
- What are all the uses of an underscore in Scala?
- Scala - Future "Out of memory"
- How to "override" an exception in scala?
- Generate Strings from Grammar in ScalaCheck
- winutils error:Error while running spark on windows
- MessageHandler in KafkaUtils010 SparkStreaming
- Create JAR for project or project-build
- Crashing the compiler with a "MatchError: AnyRef" when I call my scala macro
- Serialize / Deserialize Object To/From Delimited String
- Scala: Passing Any to a method which takes java.lang.Object
- Spark / Scala: Passing RDD to Function
- How to create Scala class with my IDEA?
- Replacing workers in BalancingPool
- ElasticClient giving NullPointerException
- SCALA Lift - Call javascript with params from Comet actor
- Create a DataFrame from a csv (url source) with scala
- Scala's "for comprehension" in Javascript
- De-normalise/Transpose spark dataframe
- Assigning Spark SQL function to variable
- i'm new to scala. can somebody tell me why i'm getting a error illicit start of simple function when writing the def recur function