Skip to content

Instantly share code, notes, and snippets.

@ubourdon
Created April 24, 2015 11:54
Show Gist options
  • Select an option

  • Save ubourdon/7da13188fa83df4d41d8 to your computer and use it in GitHub Desktop.

Select an option

Save ubourdon/7da13188fa83df4d41d8 to your computer and use it in GitHub Desktop.
polymorphic function & type alias - compilation error
package object example {
type ElasticSearchIndexation[X] = X => Future[Try[String]]
type DatabaseInsertion[Z] = Z => Future[Option[Z]]
def saveAndIndex[A](g: A => Future[Try[String]])(f: A => Future[Option[A]])(x: A): OptionT[Future, Try[String]] = ???
def saveAndIndexAlias[A](g: ElasticSearchIndexation[A])(f: DatabaseInsertion[A])(x: A): OptionT[Future, Try[String]] = ???
}
object Test {
val toto: Toto = ???
val indexTotoInES: Toto => Future[Try[String]] = ???
val insertToto: Toto => Future[Option[Toto]] = ???
toto |> saveAndIndex(indexTotoInES)(insertToto) // compile OK
toto |> saveAndIndexAlias(indexTotoInES)(insertToto) // Don't compile with errors :
/**
* type mismatch;
[error] found : Toto => scala.concurrent.Future[scala.util.Try[String]]
[error] required: example.ElasticSearchIndexation[A]
[error] (which expands to) A => scala.concurrent.Future[scala.util.Try[String]]
[error] toto |> saveAndIndexAlias(indexTotoInES)(insertToto)
*
** /
}
@jeantil
Copy link
Copy Markdown

jeantil commented Apr 28, 2015

out of curiosity does
toto |> saveAndIndexAlias[Toto](indexTotoInES)(insertToto)
compile ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment