Skip to content

Commit

Permalink
explicit implicit val/def types for scala 3 compat (#501)
Browse files Browse the repository at this point in the history
* tidy: explicit implicit val types for scala 3 migration

* tidy: explicit implicit def types for scala 3 migration
  • Loading branch information
i10416 authored Jun 19, 2023
1 parent c2b92df commit 56db96b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 74 deletions.
16 changes: 10 additions & 6 deletions modules/core/shared/src/main/scala/cron4s/CronUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ private[cron4s] trait CronUnitInstances extends CronUnits {
override def range(fL: CronUnit[F]): IndexedSeq[Int] = unit.range
}

implicit val secondsInstance = enumerated(Seconds)
implicit val minutesInstance = enumerated(Minutes)
implicit val hoursInstance = enumerated(Hours)
implicit val daysOfMonthInstance = enumerated(DaysOfMonth)
implicit val monthsInstance = enumerated(Months)
implicit val daysOfWeekInstance = enumerated(DaysOfWeek)
implicit val secondsInstance: Enumerated[CronUnit[CronField.Second]] = enumerated(Seconds)
implicit val minutesInstance: Enumerated[CronUnit[CronField.Minute]] = enumerated(Minutes)
implicit val hoursInstance: Enumerated[CronUnit[CronField.Hour]] = enumerated(Hours)
implicit val daysOfMonthInstance: Enumerated[CronUnit[CronField.DayOfMonth]] = enumerated(
DaysOfMonth
)
implicit val monthsInstance: Enumerated[CronUnit[CronField.Month]] = enumerated(Months)
implicit val daysOfWeekInstance: Enumerated[CronUnit[CronField.DayOfWeek]] = enumerated(
DaysOfWeek
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Predicate {
def apply(a: A): Boolean = f(a)
}

implicit val contravariant = new Contravariant[Predicate] {
implicit val contravariant: Contravariant[Predicate] = new Contravariant[Predicate] {
def contramap[A, B](fa: Predicate[A])(f: B => A): Predicate[B] =
Predicate(b => fa(f(b)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,27 @@ private[datetime] final class PredicateReducer[DateTime](DT: IsDateTime[DateTime
.getOrElse(M.empty[DateTime](dt))
}

implicit def caseSeconds =
implicit def caseSeconds: Case.Aux[SecondsNode, Predicate[DateTime]] =
at[SecondsNode](node => predicateFor(Second, node))
implicit def caseMinutes =
implicit def caseMinutes: Case.Aux[MinutesNode, Predicate[DateTime]] =
at[MinutesNode](node => predicateFor(Minute, node))
implicit def caseHours = at[HoursNode](node => predicateFor(Hour, node))
implicit def caseDaysOfMonth =
implicit def caseHours: Case.Aux[HoursNode, Predicate[DateTime]] =
at[HoursNode](node => predicateFor(Hour, node))
implicit def caseDaysOfMonth: Case.Aux[DaysOfMonthNode, Predicate[DateTime]] =
at[DaysOfMonthNode](node => predicateFor(DayOfMonth, node))
implicit def caseMonths = at[MonthsNode](node => predicateFor(Month, node))
implicit def caseDaysOfWeek =
implicit def caseMonths: Case.Aux[MonthsNode, Predicate[DateTime]] =
at[MonthsNode](node => predicateFor(Month, node))
implicit def caseDaysOfWeek: Case.Aux[DaysOfWeekNode, Predicate[DateTime]] =
at[DaysOfWeekNode](node => predicateFor(DayOfWeek, node))
}

object fromRaw extends Poly1 {
implicit def caseFullExpr = at[CronExpr](_.raw.map(asPredicate).toList)
implicit def caseDateExpr = at[DateCronExpr](_.raw.map(asPredicate).toList)
implicit def caseTimeExpr = at[TimeCronExpr](_.raw.map(asPredicate).toList)
implicit def caseFullExpr: Case.Aux[CronExpr, List[Predicate[DateTime]]] =
at[CronExpr](_.raw.map(asPredicate).toList)
implicit def caseDateExpr: Case.Aux[DateCronExpr, List[Predicate[DateTime]]] =
at[DateCronExpr](_.raw.map(asPredicate).toList)
implicit def caseTimeExpr: Case.Aux[TimeCronExpr, List[Predicate[DateTime]]] =
at[TimeCronExpr](_.raw.map(asPredicate).toList)
}

def run(cron: AnyCron): Predicate[DateTime] =
Expand Down
23 changes: 14 additions & 9 deletions modules/core/shared/src/main/scala/cron4s/datetime/Stepper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ private[datetime] final class Stepper[DateTime](DT: IsDateTime[DateTime]) {
} yield (identityReset, newDateTime, s.copy(amount = 0))

object stepPerNode extends Poly2 {
implicit def caseSeconds =
implicit def caseSeconds: Case.Aux[StepST, SecondsNode, StepST] =
at[StepST, SecondsNode]((step, node) => stepNode(step, node))
implicit def caseMinutes =
implicit def caseMinutes: Case.Aux[StepST, MinutesNode, StepST] =
at[StepST, MinutesNode]((step, node) => stepNode(step, node))
implicit def caseHours =
implicit def caseHours: Case.Aux[StepST, HoursNode, StepST] =
at[StepST, HoursNode]((step, node) => stepNode(step, node))
implicit def caseDaysOfMonth =
implicit def caseDaysOfMonth: Case.Aux[StepST, DaysOfMonthNode, StepST] =
at[StepST, DaysOfMonthNode]((step, node) => stepNode(step, node))
implicit def caseMonths = at[StepST, MonthsNode](stepOverMonth)
implicit def caseDaysOfWeek = at[StepST, DaysOfWeekNode](stepOverDayOfWeek)
implicit def caseMonths: Case.Aux[StepST, MonthsNode, StepST] =
at[StepST, MonthsNode](stepOverMonth)
implicit def caseDaysOfWeek: Case.Aux[StepST, DaysOfWeekNode, StepST] =
at[StepST, DaysOfWeekNode](stepOverDayOfWeek)
}

object foldInternalExpr extends Poly2 {
implicit def caseFullExpr =
implicit def caseFullExpr: Case.Aux[StepST, CronExpr, Option[(ResetPrevFn, DateTime, Step)]] =
at[StepST, CronExpr] { (stepSt, expr) =>
val dateWithoutDOW = expr.datePart.raw.take(2)
val daysOfWeekNode = expr.datePart.raw.select[DaysOfWeekNode]
Expand All @@ -122,10 +124,13 @@ private[datetime] final class Stepper[DateTime](DT: IsDateTime[DateTime]) {
result <- stepOverDayOfWeek(Some((resetTime, dt, step)), daysOfWeekNode)
} yield result
}
implicit def caseDateExpr =
implicit def caseDateExpr
: Case.Aux[StepST, DateCronExpr, Option[(DateTime => Option[DateTime], DateTime, Step)]] =
at[StepST, DateCronExpr]((stepSt, expr) => expr.raw.foldLeft(stepSt)(stepPerNode))
implicit def caseTimeExpr =
implicit def caseTimeExpr
: Case.Aux[StepST, TimeCronExpr, Option[(DateTime => Option[DateTime], DateTime, Step)]] =
at[StepST, TimeCronExpr]((stepSt, expr) => expr.raw.foldLeft(stepSt)(stepPerNode))

}

def run(cron: AnyCron, from: DateTime, step: Step): Option[DateTime] = {
Expand Down
122 changes: 81 additions & 41 deletions modules/core/shared/src/main/scala/cron4s/expr/ops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,124 @@ import cats.Show
import cron4s.CronField

import shapeless._

import cron4s.base.Predicate
import cron4s.CronUnit
/**
* Created by alonsodomin on 17/12/2016.
*/
private[cron4s] object ops {
object matches extends Poly1 {
implicit def caseEach[F <: CronField] = at[EachNode[F]](_.matches)
implicit def caseAny[F <: CronField] = at[AnyNode[F]](_.matches)
implicit def caseConst[F <: CronField] = at[ConstNode[F]](_.matches)
implicit def caseBetween[F <: CronField] = at[BetweenNode[F]](_.matches)
implicit def caseSeveral[F <: CronField] = at[SeveralNode[F]](_.matches)
implicit def caseEvery[F <: CronField] = at[EveryNode[F]](_.matches)
implicit def caseEach[F <: CronField]: Case.Aux[EachNode[F], Predicate[Int]] =
at[EachNode[F]](_.matches)
implicit def caseAny[F <: CronField]: Case.Aux[AnyNode[F], Predicate[Int]] =
at[AnyNode[F]](_.matches)
implicit def caseConst[F <: CronField]: Case.Aux[ConstNode[F], Predicate[Int]] =
at[ConstNode[F]](_.matches)
implicit def caseBetween[F <: CronField]: Case.Aux[BetweenNode[F], Predicate[Int]] =
at[BetweenNode[F]](_.matches)
implicit def caseSeveral[F <: CronField]: Case.Aux[SeveralNode[F], Predicate[Int]] =
at[SeveralNode[F]](_.matches)
implicit def caseEvery[F <: CronField]: Case.Aux[EveryNode[F], Predicate[Int]] =
at[EveryNode[F]](_.matches)

implicit def caseField[F <: CronField] =
implicit def caseField[F <: CronField]: Case.Aux[FieldNode[F], Predicate[Int]] =
at[FieldNode[F]](_.raw.fold(matches))
implicit def caseFieldWithAny[F <: CronField] =
implicit def caseFieldWithAny[F <: CronField]: Case.Aux[FieldNodeWithAny[F], Predicate[Int]] =
at[FieldNodeWithAny[F]](_.raw.fold(matches))
implicit def caseEnumerable[F <: CronField] =
implicit def caseEnumerable[F <: CronField]: Case.Aux[EnumerableNode[F], Predicate[Int]] =
at[EnumerableNode[F]](_.raw.fold(matches))
implicit def caseDivisible[F <: CronField] =
implicit def caseDivisible[F <: CronField]: Case.Aux[DivisibleNode[F], Predicate[Int]] =
at[DivisibleNode[F]](_.raw.fold(matches))
}

object range extends Poly1 {
implicit def caseEach[F <: CronField] = at[EachNode[F]](_.range)
implicit def caseAny[F <: CronField] = at[AnyNode[F]](_.range)
implicit def caseConst[F <: CronField] = at[ConstNode[F]](_.range)
implicit def caseBetween[F <: CronField] = at[BetweenNode[F]](_.range)
implicit def caseSeveral[F <: CronField] = at[SeveralNode[F]](_.range)
implicit def caseEvery[F <: CronField] = at[EveryNode[F]](_.range)
implicit def caseEach[F <: CronField]: Case.Aux[EachNode[F], IndexedSeq[Int]] =
at[EachNode[F]](_.range)
implicit def caseAny[F <: CronField]: Case.Aux[AnyNode[F], IndexedSeq[Int]] =
at[AnyNode[F]](_.range)
implicit def caseConst[F <: CronField]: Case.Aux[ConstNode[F], IndexedSeq[Int]] =
at[ConstNode[F]](_.range)
implicit def caseBetween[F <: CronField]: Case.Aux[BetweenNode[F], IndexedSeq[Int]] =
at[BetweenNode[F]](_.range)
implicit def caseSeveral[F <: CronField]: Case.Aux[SeveralNode[F], IndexedSeq[Int]] =
at[SeveralNode[F]](_.range)
implicit def caseEvery[F <: CronField]: Case.Aux[EveryNode[F], IndexedSeq[Int]] =
at[EveryNode[F]](_.range)

implicit def caseField[F <: CronField] = at[FieldNode[F]](_.raw.fold(range))
implicit def caseFieldWithAny[F <: CronField] =
implicit def caseField[F <: CronField]: Case.Aux[FieldNode[F], IndexedSeq[Int]] =
at[FieldNode[F]](_.raw.fold(range))
implicit def caseFieldWithAny[F <: CronField]: Case.Aux[FieldNodeWithAny[F], IndexedSeq[Int]] =
at[FieldNodeWithAny[F]](_.raw.fold(range))
implicit def caseEnumerable[F <: CronField] =
implicit def caseEnumerable[F <: CronField]: Case.Aux[EnumerableNode[F], IndexedSeq[Int]] =
at[EnumerableNode[F]](_.raw.fold(range))
implicit def caseDivisible[F <: CronField] =
implicit def caseDivisible[F <: CronField]: Case.Aux[DivisibleNode[F], IndexedSeq[Int]] =
at[DivisibleNode[F]](_.raw.fold(range))
}

object show extends Poly1 {
implicit def caseEach[F <: CronField](implicit show: Show[EachNode[F]]) =
implicit def caseEach[F <: CronField](implicit
show: Show[EachNode[F]]
): Case.Aux[EachNode[F], String] =
at[EachNode[F]](show.show)
implicit def caseAny[F <: CronField](implicit show: Show[AnyNode[F]]) =
implicit def caseAny[F <: CronField](implicit
show: Show[AnyNode[F]]
): Case.Aux[AnyNode[F], String] =
at[AnyNode[F]](show.show)
implicit def caseConst[F <: CronField](implicit show: Show[ConstNode[F]]) =
implicit def caseConst[F <: CronField](implicit
show: Show[ConstNode[F]]
): Case.Aux[ConstNode[F], String] =
at[ConstNode[F]](show.show)
implicit def caseBetween[F <: CronField](implicit show: Show[BetweenNode[F]]) =
implicit def caseBetween[F <: CronField](implicit
show: Show[BetweenNode[F]]
): Case.Aux[BetweenNode[F], String] =
at[BetweenNode[F]](show.show)
implicit def caseSeveral[F <: CronField](implicit show: Show[SeveralNode[F]]) =
implicit def caseSeveral[F <: CronField](implicit
show: Show[SeveralNode[F]]
): Case.Aux[SeveralNode[F], String] =
at[SeveralNode[F]](show.show)
implicit def caseEvery[F <: CronField](implicit show: Show[EveryNode[F]]) =
implicit def caseEvery[F <: CronField](implicit
show: Show[EveryNode[F]]
): Case.Aux[EveryNode[F], String] =
at[EveryNode[F]](show.show)

implicit def caseField[F <: CronField](implicit show: Show[FieldNode[F]]) =
implicit def caseField[F <: CronField](implicit
show: Show[FieldNode[F]]
): Case.Aux[FieldNode[F], String] =
at[FieldNode[F]](show.show)
implicit def caseFieldWithAny[F <: CronField](implicit show: Show[FieldNodeWithAny[F]]) =
implicit def caseFieldWithAny[F <: CronField](implicit
show: Show[FieldNodeWithAny[F]]
): Case.Aux[FieldNodeWithAny[F], String] =
at[FieldNodeWithAny[F]](show.show)
implicit def caseEnumerable[F <: CronField](implicit show: Show[EnumerableNode[F]]) =
implicit def caseEnumerable[F <: CronField](implicit
show: Show[EnumerableNode[F]]
): Case.Aux[EnumerableNode[F], String] =
at[EnumerableNode[F]](show.show)
implicit def caseDivisble[F <: CronField](implicit show: Show[DivisibleNode[F]]) =
implicit def caseDivisble[F <: CronField](implicit
show: Show[DivisibleNode[F]]
): Case.Aux[DivisibleNode[F], String] =
at[DivisibleNode[F]](show.show)
}

object unit extends Poly1 {
implicit def caseEach[F <: CronField] = at[EachNode[F]](_.unit)
implicit def caseAny[F <: CronField] = at[AnyNode[F]](_.unit)
implicit def caseConst[F <: CronField] = at[ConstNode[F]](_.unit)
implicit def caseBetween[F <: CronField] = at[BetweenNode[F]](_.unit)
implicit def caseSeveral[F <: CronField] = at[SeveralNode[F]](_.unit)
implicit def caseEvery[F <: CronField] = at[EveryNode[F]](_.unit)
implicit def caseEach[F <: CronField]: Case.Aux[EachNode[F], CronUnit[F]] =
at[EachNode[F]](_.unit)
implicit def caseAny[F <: CronField]: Case.Aux[AnyNode[F], CronUnit[F]] = at[AnyNode[F]](_.unit)
implicit def caseConst[F <: CronField]: Case.Aux[ConstNode[F], CronUnit[F]] =
at[ConstNode[F]](_.unit)
implicit def caseBetween[F <: CronField]: Case.Aux[BetweenNode[F], CronUnit[F]] =
at[BetweenNode[F]](_.unit)
implicit def caseSeveral[F <: CronField]: Case.Aux[SeveralNode[F], CronUnit[F]] =
at[SeveralNode[F]](_.unit)
implicit def caseEvery[F <: CronField]: Case.Aux[EveryNode[F], CronUnit[F]] =
at[EveryNode[F]](_.unit)

implicit def caseField[F <: CronField] = at[FieldNode[F]](_.raw.fold(unit))
implicit def caseFieldWithAny[F <: CronField] =
implicit def caseField[F <: CronField]: Case.Aux[FieldNode[F], CronUnit[F]] =
at[FieldNode[F]](_.raw.fold(unit))
implicit def caseFieldWithAny[F <: CronField]: Case.Aux[FieldNodeWithAny[F], CronUnit[F]] =
at[FieldNodeWithAny[F]](_.raw.fold(unit))
implicit def caseEnumerable[F <: CronField] =
implicit def caseEnumerable[F <: CronField]: Case.Aux[EnumerableNode[F], CronUnit[F]] =
at[EnumerableNode[F]](_.raw.fold(unit))
implicit def caseDivisible[F <: CronField] =
implicit def caseDivisible[F <: CronField]: Case.Aux[DivisibleNode[F], CronUnit[F]] =
at[DivisibleNode[F]](_.raw.fold(unit))
}
}
18 changes: 10 additions & 8 deletions modules/core/shared/src/main/scala/cron4s/validation/ops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cron4s.CronField
import cron4s.expr._

import shapeless._
import cron4s.InvalidField

/**
* Created by alonsodomin on 03/02/2017.
Expand All @@ -28,34 +29,35 @@ private[validation] object ops {
object validate extends Poly1 {
implicit def caseEach[F <: CronField](implicit
validator: NodeValidator[EachNode[F]]
) = at[EachNode[F]](validator.validate)
): Case.Aux[EachNode[F], List[InvalidField]] = at[EachNode[F]](validator.validate)

implicit def caseAny[F <: CronField](implicit
validator: NodeValidator[AnyNode[F]]
) = at[AnyNode[F]](validator.validate)
): Case.Aux[AnyNode[F], List[InvalidField]] = at[AnyNode[F]](validator.validate)

implicit def caseConst[F <: CronField](implicit
validator: NodeValidator[ConstNode[F]]
) = at[ConstNode[F]](validator.validate)
): Case.Aux[ConstNode[F], List[InvalidField]] = at[ConstNode[F]](validator.validate)

implicit def caseBetween[F <: CronField](implicit
validator: NodeValidator[BetweenNode[F]]
) = at[BetweenNode[F]](validator.validate)
): Case.Aux[BetweenNode[F], List[InvalidField]] = at[BetweenNode[F]](validator.validate)

implicit def caseSeveral[F <: CronField](implicit
validator: NodeValidator[SeveralNode[F]]
) = at[SeveralNode[F]](validator.validate)
): Case.Aux[SeveralNode[F], List[InvalidField]] = at[SeveralNode[F]](validator.validate)

implicit def caseEvery[F <: CronField](implicit
validator: NodeValidator[EveryNode[F]]
) = at[EveryNode[F]](validator.validate)
): Case.Aux[EveryNode[F], List[InvalidField]] = at[EveryNode[F]](validator.validate)

implicit def caseField[F <: CronField](implicit
validator: NodeValidator[FieldNode[F]]
) = at[FieldNode[F]](validator.validate)
): Case.Aux[FieldNode[F], List[InvalidField]] = at[FieldNode[F]](validator.validate)

implicit def caseFieldWithAny[F <: CronField](implicit
validator: NodeValidator[FieldNodeWithAny[F]]
) = at[FieldNodeWithAny[F]](validator.validate)
): Case.Aux[FieldNodeWithAny[F], List[InvalidField]] =
at[FieldNodeWithAny[F]](validator.validate)
}
}

0 comments on commit 56db96b

Please sign in to comment.