This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
core/src/main/scala/zio/constraintless/AreElementsOf.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package zio.constraintless | ||
|
||
import TypeList.{::, End} | ||
|
||
sealed trait AreElementsOf[T1 <: TypeList, T2 <: TypeList] | ||
|
||
object AreElementsOf { | ||
def apply[T1 <: TypeList, T2 <: TypeList](implicit | ||
ev: AreElementsOf[T1, T2] | ||
): AreElementsOf[T1, T2] = ev | ||
|
||
final case class TypeCollection[T1, T11 <: TypeList, T2 <: TypeList]( | ||
ev1: T1 IsElementOf T2, | ||
ev2: T11 AreElementsOf T2 | ||
) extends AreElementsOf[T1 :: T11, T2] | ||
|
||
final case class NilCollection[T2 <: TypeList]() | ||
extends AreElementsOf[End, T2] | ||
|
||
implicit def typesElementsOfTypes[Head, Tail <: TypeList, Types <: TypeList]( | ||
implicit | ||
ev1: Head IsElementOf Types, | ||
ev2: Tail AreElementsOf Types | ||
): AreElementsOf[Head :: Tail, Types] = | ||
TypeCollection(ev1, ev2) | ||
|
||
implicit def endElementOfTypes[Types <: TypeList]: AreElementsOf[End, Types] = | ||
NilCollection() | ||
|
||
} | ||
|
||
object Sample extends App { | ||
println(AreElementsOf[Int :: Double :: End, Int :: Double :: End]) | ||
println(AreElementsOf[Double :: Int :: End, Int :: Double :: Long :: End]) | ||
// println(AreElementsOf[String :: Double :: End, Int :: Double :: End]) // doesn't compiol;e | ||
} |
This file contains 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
This file contains 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