11module Data.Int.AtLeast
2- ( IntAL -- Constructor not exported. Use fromInt, fromInt' or clamp
2+ ( IntAL -- Constructor not exported. Use fromInt, fromInt' or pullUp
33 , fromInt
44 , fromInt'
5+ , pullUp
56 , fromMin
67 , clamp
78 , fromLength
@@ -21,6 +22,7 @@ module Data.Int.AtLeast
2122 , divide
2223 , weaken
2324 , strengthen
25+ , pullUp'
2426 , gcd
2527 , lcm
2628 , lengthArray
@@ -40,6 +42,7 @@ import Data.Reflectable (class Reflectable, reflectType)
4042import Partial (crashWith )
4143import Prim.Int (class Add , class Compare , class Mul )
4244import Prim.Ordering (LT )
45+ import Prim.TypeError (class Warn , Text )
4346import Test.QuickCheck.Arbitrary (class Arbitrary )
4447import Test.QuickCheck.Gen (chooseInt , elements , oneOf )
4548import Type.Proxy (Proxy (..))
@@ -97,13 +100,27 @@ fromInt' i =
97100 else crashWith $
98101 " Cannot convert Int " <> show i <> " to IntAL " <> show minInt
99102
103+ -- | Convert an `Int` to an `IntAL`, increasing the value to the type-level
104+ -- | minimum if required
105+ pullUp :: ∀ (min :: Int ). Reflectable min Int => Int -> IntAL min
106+ pullUp i =
107+ let
108+ minInt = reflectType (Proxy :: _ min )
109+ in
110+ IntAL $ if i >= minInt then i else minInt
111+
100112-- | Construct an `IntAL` equal to its type-level minimum
101113fromMin :: ∀ (min :: Int ). Reflectable min Int => IntAL min
102114fromMin = IntAL $ reflectType (Proxy :: _ min )
103115
104116-- | Convert an `Int` to an `IntAL`, increasing the value to the type-level
105117-- | minimum if required
106- clamp :: ∀ (min :: Int ). Reflectable min Int => Int -> IntAL min
118+ clamp
119+ :: ∀ (min :: Int )
120+ . Warn (Text " `clamp` is deprecated in favor of `pullUp`" )
121+ => Reflectable min Int
122+ => Int
123+ -> IntAL min
107124clamp i =
108125 let
109126 minInt = reflectType (Proxy :: _ min )
@@ -212,6 +229,15 @@ strengthen
212229 -> Maybe (IntAL min_to )
213230strengthen (IntAL i) = fromInt i
214231
232+ -- | Increase the type-level minimum value, increasing the runtime value if
233+ -- | necessary
234+ pullUp'
235+ :: ∀ (min_from :: Int ) (min_to :: Int )
236+ . Reflectable min_to Int
237+ => IntAL min_from
238+ -> IntAL min_to
239+ pullUp' (IntAL i) = pullUp i
240+
215241-- | The greatest common divisor of two IntAL values with possibly different
216242-- | type-level minimums. Limited to types with strictly positive type-level
217243-- | minimums. Returns an IntAL 1
0 commit comments