I guess it's a problem with scala compiler: it can't use Function7[...., T]
as M[T]
.
You could help to compiler this way:
type MF7[T] = (String, Option[SpaceId], Option[String], Option[Long], Option[Iterable[Long]], Option[LocalDate], Option[LocalDate]) => T
(getObj _: MF7[DBObject]).map(myMatch)
Note that you should avoid $
in names. $
is widely used in scala for generated names.
map
works for Function6
, so you could just reduce parameters cont. For instance you could group parameters using case class
:
case class Period(startDate: Option[LocalDate] = None, endDate: Option[LocalDate] = None)
def getObj(instance: String, contextValue: Option[SpaceId] = None,
eventType: Option[String] = None, sourceValue: Option[Long] = None,
targetValues: Option[Iterable[Long]] = None,
period: Option[Period] = None) : DBObject = ???
val getMatchObj = (getObj _).map(myMatch)
shapeless
With shapeless
you could convert function of any arity to function of single HList
argument and vice versa:
val getMatchObj = (getObj _).toProduct.andThen(myMatch).fromProduct
Default parameters
scala
functions can't have default parameters, so the only way to preserve default parameters is to extract all parameters to case class
like this:
case class GetObjArgs(instance: String, contextValue: Option[SpaceId] = None,
eventType: Option[String] = None, sourceValue: Option[Long] = None,
targetValues: Option[Iterable[Long]] = None,
startDate: Option[LocalDate] = None, endDate: Option[LocalDate] = None)
def getObj(a: GetObjArgs): DBObject = ???
val getMatchObj = (getObj _) andThen myMatch
getMatchObj(GetObjArgs("inst", sourceValue = Some(1)))