unapply

What are the limitations on inference of higher-kinded types in Scala?

不问归期 提交于 2019-11-29 21:48:13
In the following simplified sample code: case class One[A](a: A) // An identity functor case class Twice[F[_], A](a: F[A], b: F[A]) // A functor transformer type Twice1[F[_]] = ({type L[α] = Twice[F, α]}) // We'll use Twice1[F]#L when we'd like to write Twice[F] trait Applicative[F[_]] // Members omitted val applicativeOne: Applicative[One] = null // Implementation omitted def applicativeTwice[F[_]](implicit inner: Applicative[F]): Applicative[({type L[α] = Twice[F, α]})#L] = null I can call applicativeTwice on applicativeOne, and type inference works, as soon as I try to call it on

What are the limitations on inference of higher-kinded types in Scala?

一笑奈何 提交于 2019-11-28 17:39:54
问题 In the following simplified sample code: case class One[A](a: A) // An identity functor case class Twice[F[_], A](a: F[A], b: F[A]) // A functor transformer type Twice1[F[_]] = ({type L[α] = Twice[F, α]}) // We'll use Twice1[F]#L when we'd like to write Twice[F] trait Applicative[F[_]] // Members omitted val applicativeOne: Applicative[One] = null // Implementation omitted def applicativeTwice[F[_]](implicit inner: Applicative[F]): Applicative[({type L[α] = Twice[F, α]})#L] = null I can call

Can extractors be customized with parameters in the body of a case statement (or anywhere else that an extractor would be used)?

时光毁灭记忆、已成空白 提交于 2019-11-27 23:37:06
Basically, I would like to be able to build a custom extractor without having to store it in a variable prior to using it. This isn't a real example of how I would use it, it would more likely be used in the case of a regular expression or some other string pattern like construct, but hopefully it explains what I'm looking for: def someExtractorBuilder(arg:Boolean) = new { def unapply(s:String):Option[String] = if(arg) Some(s) else None } //I would like to be able to use something like this val {someExtractorBuilder(true)}(result) = "test" "test" match {case {someExtractorBuilder(true)}(result