From c00b469a6873c367ba846fb01be3a8e0381e9ef7 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Sun, 27 Jan 2019 23:08:38 +0900 Subject: [PATCH] Enable `rootOption` on `FilePath` --- .../instances/ConvertibleInstances.scala | 4 ++-- .../eyrie/instances/DescendantInstances.scala | 23 +++++++++++-------- .../instances/DiSuccessorInstances.scala | 8 +++---- .../instances/SubdivisionInstances.scala | 4 ++-- .../eyrie/instances/SuccessorInstances.scala | 6 +++-- .../file/test/PotentialDescendantSpec.scala | 10 +++++++- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/core/src/main/scala/eyrie/instances/ConvertibleInstances.scala b/core/src/main/scala/eyrie/instances/ConvertibleInstances.scala index 595bd7f..497bc25 100644 --- a/core/src/main/scala/eyrie/instances/ConvertibleInstances.scala +++ b/core/src/main/scala/eyrie/instances/ConvertibleInstances.scala @@ -4,7 +4,7 @@ import eyrie.ops.Convertible private[eyrie] trait ConvertibleByAttributeInstances { - implicit def eyrieByAttributeInstance[Attr[_], A, B]( + implicit def eyrieConvertibleByAttributeInstance[Attr[_], A, B]( implicit F: Convertible.Aux[Attr, _, A, B] ): Convertible.ByAttribute.Aux[Attr, A, B] = new Convertible.ByAttribute[Attr, A] { @@ -23,7 +23,7 @@ trait ConvertibleByAttributeInstances { private[eyrie] trait ConvertibleByQualityInstances { - implicit def eyrieByQualityInstance[Attr[_], Param, A, B]( + implicit def eyrieConvertibleByQualityInstance[Attr[_], Param, A, B]( implicit F: Convertible.Aux[Attr, Param, A, B] ): Convertible.ByQuality.Aux[Attr[Param], A, B] = new Convertible.ByQuality[Attr[Param], B] { diff --git a/core/src/main/scala/eyrie/instances/DescendantInstances.scala b/core/src/main/scala/eyrie/instances/DescendantInstances.scala index 1438c4b..7144e8c 100644 --- a/core/src/main/scala/eyrie/instances/DescendantInstances.scala +++ b/core/src/main/scala/eyrie/instances/DescendantInstances.scala @@ -8,7 +8,7 @@ import scala.Function.const private[eyrie] trait DescendantInstances { - implicit def eyrieSubdivisionBasedInstance[A, LA, RA, B]( + implicit def eyrieDescendantBasedInstance[A, LA, RA, B]( implicit A: Subdivision[A, LA, RA], LA: Descendant[LA, B], @@ -19,10 +19,18 @@ trait DescendantInstances { def root: A => B = A.subdivide(_).fold(LA.root, RA.root) } + + implicit def eyrieNonDescendantBasedInstance[A, LA, RA]( + implicit + A: Subdivision[A, LA, RA], + LA: NonDescendant[LA], + RA: NonDescendant[RA] + ): NonDescendant[A] = + eyrieDescendantBasedInstance[A, LA, RA, Nothing] } private[eyrie] -trait DescendantByInputInstances extends LowPriorityDescendantByInputInstances { +trait DescendantByInputInstances { implicit def eyrieTrivialByInputInstance[A]( implicit A: TrivialDescendant[A] ): Descendant.ByInput.Aux[A, A] = @@ -39,11 +47,8 @@ trait DescendantByInputInstances extends LowPriorityDescendantByInputInstances { def root: A => A = A.root } -} -private[eyrie] -trait LowPriorityDescendantByInputInstances { - implicit def eyrieByInputInstance[A, B]( + implicit def eyrieDescendantByInputInstance[A, B]( implicit A: Descendant[A, B] ): Descendant.ByInput.Aux[A, B] = new Descendant.ByInput[A] { @@ -58,7 +63,7 @@ trait LowPriorityDescendantByInputInstances { private[eyrie] trait PotentialDescendantInstances { - implicit def eyrieLeftSubdivisionBasedInstance[A, LA, RA, B]( + implicit def eyrieLeftDescendantBasedInstance[A, LA, RA, B]( implicit A: Subdivision[A, LA, RA], LA: Descendant[LA, B], @@ -70,7 +75,7 @@ trait PotentialDescendantInstances { A.subdivide(_).fold(LA.root >>> (Some(_)), const(None)) } - implicit def eyrieRightSubdivisionBasedInstance[A, LA, RA, B]( + implicit def eyrieRightDescendantBasedInstance[A, LA, RA, B]( implicit A: Subdivision[A, LA, RA], LA: NonDescendant[LA], @@ -85,7 +90,7 @@ trait PotentialDescendantInstances { private[eyrie] trait PotentialDescendantByInputInstances { - implicit def eyrieByInputInstance[A, D]( + implicit def eyriePotentialDescendantByInputInstance[A, D]( implicit A: PotentialDescendant[A, D] ): PotentialDescendant.ByInput.Aux[A, D] = new PotentialDescendant.ByInput[A] { diff --git a/core/src/main/scala/eyrie/instances/DiSuccessorInstances.scala b/core/src/main/scala/eyrie/instances/DiSuccessorInstances.scala index 9f8463c..e27f3f3 100644 --- a/core/src/main/scala/eyrie/instances/DiSuccessorInstances.scala +++ b/core/src/main/scala/eyrie/instances/DiSuccessorInstances.scala @@ -7,7 +7,7 @@ import eyrie.ops._ private[eyrie] trait DiSuccessorInstances { - implicit def eyrieSubdivisionBasedInstance[A, LA, RA, LB, RB, C]( + implicit def eyrieSuccessorBasedInstance[A, LA, RA, LB, RB, C]( implicit A: Subdivision[A, LA, RA], LA: Successor[LA, LB, C], @@ -26,7 +26,7 @@ trait DiSuccessorInstances { private[eyrie] trait DiSuccessorByInputInstances { - implicit def eyrieByInputInstance[A, L, R, C]( + implicit def eyrieDiSuccessorByInputInstance[A, L, R, C]( implicit A: DiSuccessor[A, L, R, C] ): DiSuccessor.ByInput.Aux[A, L, R, C] = new DiSuccessor.ByInput[A] { @@ -49,7 +49,7 @@ trait DiSuccessorByInputInstances { private[eyrie] trait DiPotentialSuccessorInstances { - implicit def eyrieSubdivisionBasedInstance[A, L, R, C]( + implicit def eyriePotentialSuccessorBasedInstance[A, L, R, C]( implicit A: Subdivision[A, L, R], L: PotentialSuccessor[L, C], @@ -68,7 +68,7 @@ trait DiPotentialSuccessorInstances { private[eyrie] trait DiPotentialSuccessorByInputInstances { - implicit def eyrieByInputInstance[A, L, R, C]( + implicit def eyrieDiPotentialSuccessorByInputInstance[A, L, R, C]( implicit A: DiPotentialSuccessor[A, L, R, C] ): DiPotentialSuccessor.ByInput.Aux[A, L, R, C] = new DiPotentialSuccessor.ByInput[A] { diff --git a/core/src/main/scala/eyrie/instances/SubdivisionInstances.scala b/core/src/main/scala/eyrie/instances/SubdivisionInstances.scala index c891adf..35dcef9 100644 --- a/core/src/main/scala/eyrie/instances/SubdivisionInstances.scala +++ b/core/src/main/scala/eyrie/instances/SubdivisionInstances.scala @@ -4,7 +4,7 @@ import eyrie.ops.Subdivision private[eyrie] trait SubdivisionByAttributeInstances { - implicit def eyrieByAttributeInstance[Attr[_], A, L, R]( + implicit def eyrieSubdivisionByAttributeInstance[Attr[_], A, L, R]( implicit F: Subdivision.Aux[Attr, A, L, R] ): Subdivision.ByAttribute.Aux[Attr, A, L, R] = new Subdivision.ByAttribute[Attr, A] { @@ -21,7 +21,7 @@ trait SubdivisionByAttributeInstances { private[eyrie] trait SubdivisionByInputInstances { - implicit def eyrieByInputInstance[Attr[_], A, L, R]( + implicit def eyrieSubdivisionByInputInstance[Attr[_], A, L, R]( implicit F: Subdivision.Aux[Attr, A, L, R] ): Subdivision.ByInput.Aux[Attr, A, L, R] = new Subdivision.ByInput[A] { diff --git a/core/src/main/scala/eyrie/instances/SuccessorInstances.scala b/core/src/main/scala/eyrie/instances/SuccessorInstances.scala index 806e824..36517a0 100644 --- a/core/src/main/scala/eyrie/instances/SuccessorInstances.scala +++ b/core/src/main/scala/eyrie/instances/SuccessorInstances.scala @@ -25,7 +25,7 @@ trait SuccessorInstances { private[eyrie] trait SuccessorByInputInstances { - implicit def eyrieByInputInstance[A, B, C](implicit A: Successor[A, B, C]): Successor.ByInput.Aux[A, B, C] = + implicit def eyrieSuccessorByInputInstance[A, B, C](implicit A: Successor[A, B, C]): Successor.ByInput.Aux[A, B, C] = new Successor.ByInput[A] { override type Prefix = B @@ -76,7 +76,9 @@ trait PotentialSuccessorInstances { private[eyrie] trait PotentialSuccessorByInputInstances { - implicit def eyrieByInputInstance[A, C](implicit A: PotentialSuccessor[A, C]): PotentialSuccessor.ByInput.Aux[A, C] = + implicit def eyriePotentialSuccessorByInputInstance[A, C]( + implicit A: PotentialSuccessor[A, C] + ): PotentialSuccessor.ByInput.Aux[A, C] = new PotentialSuccessor.ByInput[A] { override type Segment = C diff --git a/file/src/test/scala/eyrie/file/test/PotentialDescendantSpec.scala b/file/src/test/scala/eyrie/file/test/PotentialDescendantSpec.scala index 1e7a17c..06a25e4 100644 --- a/file/src/test/scala/eyrie/file/test/PotentialDescendantSpec.scala +++ b/file/src/test/scala/eyrie/file/test/PotentialDescendantSpec.scala @@ -12,6 +12,9 @@ import org.scalatest.junit.JUnitRunner object PotentialDescendantSpec { val nonEmpty: FilePath.NonEmpty[Sys] = Internal.AbsoluteFile(Paths.get("a/b/c").toAbsolutePath) + + val filePath: FilePath[Sys] = + Internal.RootDirectory(Paths.get("a/b/c").getRoot) } @RunWith(classOf[JUnitRunner]) @@ -19,9 +22,14 @@ class PotentialDescendantSpec extends FreeSpec { import PotentialDescendantSpec._ import eyrie.syntax.potentialDescendant._ - "File.Absolute" - { + "FilePath.Absolute" - { "rootOption should be Option of RootDirectory" in { nonEmpty.rootOption: Option[RootDirectory[Sys]] } } + "FilePath" - { + "rootOption should be Option of RootDirectory" in { + filePath.rootOption: Option[RootDirectory[Sys]] + } + } }