Scala multi-partition card type mismatch; Found (A, B) => Requires Boolean (A, B) => Boolean?

I am trying to split a map based on a list of predicates.

I wrote the following function for this:

def multipartition[A,B](map : Map[A,B], list : List[(A,B) => Boolean]) : List[Map[A,B]] = list match { case Nil => Nil case l :: ls => val (a, b) = map partition l; // type mismatch; found (A,B) => Boolean, required: (A,B) => Boolean return a :: multipartition(b, ls) } 

The scala compiler (I execute 2.9.1) fails at the specified location with "type mismatch", found (A, B) => Boolean, required: (A, B) => Boolean ".

Has anyone ever seen something like this? Any idea how to fix this?

Thanks,

LP

+6
source share
2 answers

partition expects Function[(A,B), Boolean] , that is, the function of the paired argument is one , and not the function of the two arguments (quite annoying that they are different)

So you need to write ((A,B)) => Boolean as the type of your list items

(The error message is generally not useful, next to a minor error)

+11
source

In addition to didierd , you can solve this by writing it like this:

  val (a, b) = map partition l.tupled; 
+7
source

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


All Articles