Skip to content

Commit 4a3a633

Browse files
committed
Merge remote-tracking branch 'origin/topic/epoch' into topic/scala3
2 parents 695077c + e256566 commit 4a3a633

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

modules/core/shared/src/main/scala-2/lucuma/core/math/Epoch.scala renamed to modules/core/shared/src/main/scala/lucuma/core/math/Epoch.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import eu.timepit.refined.cats._
1313
import eu.timepit.refined.numeric.{ Interval => RefinedInterval }
1414
import eu.timepit.refined.refineV
1515
import lucuma.core.math.parser.EpochParsers
16+
import lucuma.core.math.refined.refineMV
1617
import lucuma.core.optics.Format
1718
import lucuma.core.optics.syntax.all._
1819
import lucuma.core.syntax.parser._
@@ -78,13 +79,13 @@ object Epoch extends EpochOptics {
7879
* Standard epoch.
7980
* @group Constructors
8081
*/
81-
val J2000: Epoch = Julian.fromIntegralYears(refineMV[Year](2000))
82+
val J2000: Epoch = Julian.fromIntegralYears(refineMV[Int, Year](2000))
8283

8384
/**
8485
* Standard epoch prior to J2000. Obsolete but still in use.
8586
* @group Constructors
8687
*/
87-
val B1950: Epoch = Besselian.fromIntegralYears(refineMV[Year](1950))
88+
val B1950: Epoch = Besselian.fromIntegralYears(refineMV[Int, Year](1950))
8889

8990
/**
9091
* The scheme defines year zero and length of a year in terms of Julian days. There are two

modules/core/shared/src/main/scala-2/lucuma/core/math/JulianDate.scala renamed to modules/core/shared/src/main/scala/lucuma/core/math/JulianDate.scala

File renamed without changes.

modules/core/shared/src/main/scala-2/lucuma/core/math/parser/Epoch.scala renamed to modules/core/shared/src/main/scala/lucuma/core/math/parser/Epoch.scala

File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2016-2022 Association of Universities for Research in Astronomy, Inc. (AURA)
2+
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
3+
4+
package lucuma.core.math.refined
5+
6+
import eu.timepit.refined.api.Refined
7+
import eu.timepit.refined.numeric.Interval
8+
9+
import scala.compiletime.constValue
10+
11+
inline def refineMV[T, P](inline t: T)(using inline p: Predicate[T, P]): Refined[T, P] = {
12+
inline if (p.isValid(t)) Refined.unsafeApply(t) else scala.compiletime.error("no")
13+
}
14+
15+
trait Predicate[T, P] {
16+
transparent inline def isValid(inline t: T): Boolean
17+
}
18+
19+
object Predicate {
20+
21+
inline given [M <: Int, N <: Int]: Predicate[Int, Interval.Closed[M, N]] with
22+
transparent inline def isValid(inline t: Int): Boolean = constValue[M] <= t && t <= constValue[N]
23+
}

0 commit comments

Comments
 (0)