This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recreateIndex[F[_]: Monad](name: String)(implicit interpreter: IndexDsl[F]) = { | |
val newIndex = for { | |
_ <- EitherT(interpreter.deleteIndex(name)) | |
created <- EitherT(interpreter.createIndex(name)) | |
} yield created | |
newIndex.value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait IndexDsl[F[_]] { | |
def createIndex(name: String): F[Either[String, CreateIndexResponse]] | |
def deleteIndex(name: String): F[Either[String, DeleteIndexResponse]] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def caseClassGenerator[T, L <: HList](implicit generic: Generic.Aux[T, L], lGen: Generator[L]): Generator[T] = | |
new Generator[T] { | |
override def generate = generic.from(lGen.generate) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error:(29, 40) illegal dependent method type: parameter may only be referenced in a subsequent parameter section |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def caseClassGenerator[T, L <: HList](implicit generic: Generic[T], lGen: Generator[generic.Repr]):Generator[T] = | |
new Generator[T] { | |
override def generate = generic.from(lGen.generate) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Repr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
case class Capybara(name: String, age: Int, awesome: Boolean) | |
val genericCapy = Generic[Capybara] | |
val hlistCapy = genericCapybara.to(Generator.generate[Capybara]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Generic[T] extends Serializable { | |
/** The generic representation type for {T}, which will be composed of {Coproduct} and {HList} types */ | |
type Repr | |
/** Convert an instance of the concrete type to the generic value representation */ | |
def to(t : T) : Repr | |
/** Convert an instance of the generic representation to an instance of the concrete type */ | |
def from(r : Repr) : T | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def hnilGenerator = new Generator[HNil] { | |
override def generate = HNil | |
} | |
implicit def hlistGenerator[H, T <: HList](implicit headGen: Generator[H], tailGen: Generator[T]) = | |
new Generator[H :: T] { | |
override def generate = headGen.gen :: tailGen.gen | |
} |