File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ module Data.Enum
15
15
16
16
import Prelude
17
17
18
+ import Control.MonadPlus (guard )
19
+
18
20
import Data.Char (fromCharCode , toCharCode )
19
21
import Data.Either (Either (..))
20
22
import Data.Maybe (Maybe (..), maybe , fromJust )
@@ -93,12 +95,15 @@ defaultSucc toEnum' fromEnum' a = toEnum' (fromEnum' a + 1)
93
95
defaultPred :: forall a . (Int -> Maybe a ) -> (a -> Int ) -> a -> Maybe a
94
96
defaultPred toEnum' fromEnum' a = toEnum' (fromEnum' a - 1 )
95
97
96
- -- | Property: ```fromEnum a = a', fromEnum b = b' => forall e', a' <= e' <= b': Exists e: toEnum e' = Just e```
97
- -- |
98
- -- | Following from the propery of `intFromTo`, we are sure all elements in `intFromTo (fromEnum a) (fromEnum b)` are `Just`s.
99
- -- TODO need to update the doc comment above
98
+ -- | Returns a successive sequence of elements from the lower bound to
99
+ -- | the upper bound (inclusive).
100
100
enumFromTo :: forall a u . (Enum a , Unfoldable u ) => a -> a -> u a
101
- enumFromTo from to = unfoldr (\x -> succ x >>= \x' -> if x <= to then pure $ Tuple x x' else Nothing ) from
101
+ enumFromTo from to = unfoldr go (Just from)
102
+ where
103
+ go mx = do
104
+ x <- mx
105
+ guard (x <= to)
106
+ pure $ Tuple x (succ x)
102
107
103
108
-- | `[a,b..c]`
104
109
enumFromThenTo :: forall a . BoundedEnum a => a -> a -> a -> Array a
You can’t perform that action at this time.
0 commit comments