module Streamly.Internal.Data.Unfold.Enumeration
(
Enumerable (..)
, enumerateFromStepNum
, enumerateFromNum
, enumerateFromThenNum
, enumerateFromStepIntegral
, enumerateFromIntegral
, enumerateFromThenIntegral
, enumerateFromToIntegral
, enumerateFromThenToIntegral
, enumerateFromIntegralBounded
, enumerateFromThenIntegralBounded
, enumerateFromToIntegralBounded
, enumerateFromThenToIntegralBounded
, enumerateFromSmallBounded
, enumerateFromThenSmallBounded
, enumerateFromToSmall
, enumerateFromThenToSmall
, enumerateFromFractional
, enumerateFromThenFractional
, enumerateFromToFractional
, enumerateFromThenToFractional
)
where
#include "inline.hs"
import Data.Fixed
import Data.Bifunctor (bimap)
import Data.Int
import Data.Ratio
import Data.Word
import Numeric.Natural
import Data.Functor.Identity (Identity(..))
import Streamly.Internal.Data.Stream.StreamD.Step (Step(..))
import Streamly.Internal.Data.Unfold.Type
import Prelude
hiding (map, mapM, takeWhile, take, filter, const, zipWith
, drop, dropWhile)
{-# INLINE enumerateFromStepNum #-}
enumerateFromStepNum :: (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum :: forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum = forall (m :: * -> *) a b s.
(s -> m (Step s b)) -> (a -> m s) -> Unfold m a b
Unfold forall {m :: * -> *} {c}.
(Monad m, Num c) =>
(c, c, c) -> m (Step (c, c, c) c)
step forall {m :: * -> *} {c} {a} {b}.
(Monad m, Num c) =>
(a, b) -> m (a, b, c)
inject
where
inject :: (a, b) -> m (a, b, c)
inject (!a
from, !b
stride) = forall (m :: * -> *) a. Monad m => a -> m a
return (a
from, b
stride, c
0)
{-# INLINE_LATE step #-}
step :: (c, c, c) -> m (Step (c, c, c) c)
step (c
from, c
stride, c
i) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
(forall s a. a -> s -> Step s a
Yield forall a b. (a -> b) -> a -> b
$! (c
from forall a. Num a => a -> a -> a
+ c
i forall a. Num a => a -> a -> a
* c
stride)) forall a b. (a -> b) -> a -> b
$! (c
from, c
stride, c
i forall a. Num a => a -> a -> a
+ c
1)
{-# INLINE enumerateFromThenNum #-}
enumerateFromThenNum :: (Monad m, Num a) => Unfold m (a, a) a
enumerateFromThenNum :: forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromThenNum =
forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\(a
from, a
next) -> (a
from, a
next forall a. Num a => a -> a -> a
- a
from)) forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum
{-# INLINE enumerateFromNum #-}
enumerateFromNum :: (Monad m, Num a) => Unfold m a a
enumerateFromNum :: forall (m :: * -> *) a. (Monad m, Num a) => Unfold m a a
enumerateFromNum = forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\a
from -> (a
from, a
1)) forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum
{-# INLINE_NORMAL enumerateFromStepIntegral #-}
enumerateFromStepIntegral :: (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral :: forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral = forall (m :: * -> *) a b s.
(s -> m (Step s b)) -> (a -> m s) -> Unfold m a b
Unfold forall {m :: * -> *} {b}.
(Monad m, Num b) =>
(b, b) -> m (Step (b, b) b)
step forall {m :: * -> *} {a} {b}. Monad m => (a, b) -> m (a, b)
inject
where
inject :: (a, b) -> m (a, b)
inject (a
from, b
stride) = a
from seq :: forall a b. a -> b -> b
`seq` b
stride seq :: forall a b. a -> b -> b
`seq` forall (m :: * -> *) a. Monad m => a -> m a
return (a
from, b
stride)
{-# INLINE_LATE step #-}
step :: (b, b) -> m (Step (b, b) b)
step (b
x, b
stride) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
x forall a b. (a -> b) -> a -> b
$! (b
x forall a. Num a => a -> a -> a
+ b
stride, b
stride)
{-# INLINE enumerateFromIntegral #-}
enumerateFromIntegral :: (Monad m, Integral a) => Unfold m a a
enumerateFromIntegral :: forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m a a
enumerateFromIntegral = forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\a
from -> (a
from, a
1)) forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral
{-# INLINE enumerateFromThenIntegral #-}
enumerateFromThenIntegral :: (Monad m, Integral a ) => Unfold m (a, a) a
enumerateFromThenIntegral :: forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromThenIntegral =
forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\(a
from, a
next) -> (a
from, a
next forall a. Num a => a -> a -> a
- a
from)) forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral
{-# INLINE enumerateFromToIntegral #-}
enumerateFromToIntegral :: (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromToIntegral :: forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromToIntegral =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput (\(a
_, a
to) a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ a
b forall a. Ord a => a -> a -> Bool
<= a
to)
forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\(a
from, a
_) -> (a
from, a
1)) forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral
{-# INLINE enumerateFromThenToIntegral #-}
enumerateFromThenToIntegral :: (Monad m, Integral a) => Unfold m (a, a, a) a
enumerateFromThenToIntegral :: forall (m :: * -> *) a.
(Monad m, Integral a) =>
Unfold m (a, a, a) a
enumerateFromThenToIntegral =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput forall {m :: * -> *} {a} {a}.
(Monad m, Ord a, Ord a) =>
(a, a, a) -> a -> m Bool
cond forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {b} {c}. Num b => (b, b, c) -> (b, b)
toFromStep forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral
where
toFromStep :: (b, b, c) -> (b, b)
toFromStep (b
from, b
next, c
_) = (b
from, b
next forall a. Num a => a -> a -> a
- b
from)
cond :: (a, a, a) -> a -> m Bool
cond (a
from, a
next, a
to) a
b =
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ if a
next forall a. Ord a => a -> a -> Bool
>= a
from
then a
b forall a. Ord a => a -> a -> Bool
<= a
to
else a
b forall a. Ord a => a -> a -> Bool
>= a
to
{-# INLINE enumerateFromIntegralBounded #-}
enumerateFromIntegralBounded :: (Monad m, Integral a, Bounded a) =>
Unfold m a a
enumerateFromIntegralBounded :: forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m a a
enumerateFromIntegralBounded = forall b (m :: * -> *) a c. b -> Unfold m (a, b) c -> Unfold m a c
supplySecond forall a. Bounded a => a
maxBound forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromToIntegral
{-# INLINE enumerateFromThenIntegralBounded #-}
enumerateFromThenIntegralBounded :: (Monad m, Integral a, Bounded a ) =>
Unfold m (a, a) a
enumerateFromThenIntegralBounded :: forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m (a, a) a
enumerateFromThenIntegralBounded =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput forall {m :: * -> *} {a} {a}.
(Monad m, Ord a, Ord a, Bounded a) =>
(a, a) -> a -> m Bool
cond forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {b}. Num b => (b, b) -> (b, b)
toFromStep forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromStepIntegral
where
toFromStep :: (b, b) -> (b, b)
toFromStep (b
from, b
next) = (b
from, b
next forall a. Num a => a -> a -> a
- b
from)
cond :: (a, a) -> a -> m Bool
cond (a
from, a
next) a
b =
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ if a
next forall a. Ord a => a -> a -> Bool
>= a
from
then a
b forall a. Ord a => a -> a -> Bool
<= forall a. Bounded a => a
maxBound
else a
b forall a. Ord a => a -> a -> Bool
>= forall a. Bounded a => a
minBound
{-# INLINE enumerateFromToIntegralBounded #-}
enumerateFromToIntegralBounded :: (Monad m, Integral a, Bounded a) =>
Unfold m (a, a) a
enumerateFromToIntegralBounded :: forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m (a, a) a
enumerateFromToIntegralBounded =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput (\(a
_, a
to) a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ a
b forall a. Ord a => a -> a -> Bool
<= a
to)
forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall a b. (a, b) -> a
fst forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m a a
enumerateFromIntegralBounded
{-# INLINE enumerateFromThenToIntegralBounded #-}
enumerateFromThenToIntegralBounded :: (Monad m, Integral a, Bounded a) =>
Unfold m (a, a, a) a
enumerateFromThenToIntegralBounded :: forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m (a, a, a) a
enumerateFromThenToIntegralBounded =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput forall {m :: * -> *} {a} {a}.
(Monad m, Ord a, Ord a) =>
(a, a, a) -> a -> m Bool
cond forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {a} {b} {c}. (a, b, c) -> (a, b)
toFromThen forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
Unfold m (a, a) a
enumerateFromThenIntegralBounded
where
toFromThen :: (a, b, c) -> (a, b)
toFromThen (a
from, b
next, c
_) = (a
from, b
next)
cond :: (a, a, a) -> a -> m Bool
cond (a
from, a
next, a
to) a
b =
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ if a
next forall a. Ord a => a -> a -> Bool
>= a
from
then a
b forall a. Ord a => a -> a -> Bool
<= a
to
else a
b forall a. Ord a => a -> a -> Bool
>= a
to
{-# INLINE_NORMAL enumerateFromFractional #-}
enumerateFromFractional :: (Monad m, Fractional a) => Unfold m a a
enumerateFromFractional :: forall (m :: * -> *) a. (Monad m, Fractional a) => Unfold m a a
enumerateFromFractional = forall (m :: * -> *) a. (Monad m, Num a) => Unfold m a a
enumerateFromNum
{-# INLINE_NORMAL enumerateFromThenFractional #-}
enumerateFromThenFractional :: (Monad m, Fractional a) => Unfold m (a, a) a
enumerateFromThenFractional :: forall (m :: * -> *) a.
(Monad m, Fractional a) =>
Unfold m (a, a) a
enumerateFromThenFractional = forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromThenNum
{-# INLINE_NORMAL enumerateFromToFractional #-}
enumerateFromToFractional :: (Monad m, Fractional a, Ord a) =>
Unfold m (a, a) a
enumerateFromToFractional :: forall (m :: * -> *) a.
(Monad m, Fractional a, Ord a) =>
Unfold m (a, a) a
enumerateFromToFractional =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput (\(a
_, a
to) a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ a
b forall a. Ord a => a -> a -> Bool
<= a
to forall a. Num a => a -> a -> a
+ a
1 forall a. Fractional a => a -> a -> a
/ a
2)
forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (\(a
from, a
_) -> (a
from, a
1)) forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum
{-# INLINE enumerateFromThenToFractional #-}
enumerateFromThenToFractional :: (Monad m, Fractional a, Ord a) =>
Unfold m (a, a, a) a
enumerateFromThenToFractional :: forall (m :: * -> *) a.
(Monad m, Fractional a, Ord a) =>
Unfold m (a, a, a) a
enumerateFromThenToFractional =
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m Bool) -> Unfold m a b -> Unfold m a b
takeWhileMWithInput forall {m :: * -> *} {a}.
(Monad m, Ord a, Fractional a) =>
(a, a, a) -> a -> m Bool
cond forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {b} {c}. Num b => (b, b, c) -> (b, b)
toFromStep forall (m :: * -> *) a. (Monad m, Num a) => Unfold m (a, a) a
enumerateFromStepNum
where
toFromStep :: (b, b, c) -> (b, b)
toFromStep (b
from, b
next, c
_) = (b
from, b
next forall a. Num a => a -> a -> a
- b
from)
cond :: (a, a, a) -> a -> m Bool
cond (a
from, a
next, a
to) a
b =
let stride :: a
stride = a
next forall a. Num a => a -> a -> a
- a
from
in forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ if a
next forall a. Ord a => a -> a -> Bool
>= a
from
then a
b forall a. Ord a => a -> a -> Bool
<= a
to forall a. Num a => a -> a -> a
+ a
stride forall a. Fractional a => a -> a -> a
/ a
2
else a
b forall a. Ord a => a -> a -> Bool
>= a
to forall a. Num a => a -> a -> a
+ a
stride forall a. Fractional a => a -> a -> a
/ a
2
{-# INLINE enumerateFromToSmall #-}
enumerateFromToSmall :: (Monad m, Enum a) => Unfold m (a, a) a
enumerateFromToSmall :: forall (m :: * -> *) a. (Monad m, Enum a) => Unfold m (a, a) a
enumerateFromToSmall =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum (forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall a. Enum a => a -> Int
fromEnum forall a. Enum a => a -> Int
fromEnum) forall (m :: * -> *) a. (Monad m, Integral a) => Unfold m (a, a) a
enumerateFromToIntegral)
{-# INLINE enumerateFromThenToSmall #-}
enumerateFromThenToSmall :: (Monad m, Enum a) => Unfold m (a, a, a) a
enumerateFromThenToSmall :: forall (m :: * -> *) a. (Monad m, Enum a) => Unfold m (a, a, a) a
enumerateFromThenToSmall =
let toInts :: (a, a, a) -> (Int, Int, Int)
toInts (a
x, a
y, a
z) = (forall a. Enum a => a -> Int
fromEnum a
x, forall a. Enum a => a -> Int
fromEnum a
y, forall a. Enum a => a -> Int
fromEnum a
z)
in forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum (forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {a} {a} {a}.
(Enum a, Enum a, Enum a) =>
(a, a, a) -> (Int, Int, Int)
toInts forall (m :: * -> *) a.
(Monad m, Integral a) =>
Unfold m (a, a, a) a
enumerateFromThenToIntegral)
{-# INLINE enumerateFromSmallBounded #-}
enumerateFromSmallBounded :: (Monad m, Enum a, Bounded a) => Unfold m a a
enumerateFromSmallBounded :: forall (m :: * -> *) a.
(Monad m, Enum a, Bounded a) =>
Unfold m a a
enumerateFromSmallBounded = forall b (m :: * -> *) a c. b -> Unfold m (a, b) c -> Unfold m a c
supplySecond forall a. Bounded a => a
maxBound forall (m :: * -> *) a. (Monad m, Enum a) => Unfold m (a, a) a
enumerateFromToSmall
{-# INLINE enumerateFromThenSmallBounded #-}
enumerateFromThenSmallBounded :: forall m a. (Monad m, Enum a, Bounded a) =>
Unfold m (a, a) a
enumerateFromThenSmallBounded :: forall (m :: * -> *) a.
(Monad m, Enum a, Bounded a) =>
Unfold m (a, a) a
enumerateFromThenSmallBounded =
let adapt :: (a, b) -> (Int, Int, Int)
adapt (a
from, b
next) =
let frm :: Int
frm = forall a. Enum a => a -> Int
fromEnum a
from
nxt :: Int
nxt = forall a. Enum a => a -> Int
fromEnum b
next
stride :: Int
stride = Int
nxt forall a. Num a => a -> a -> a
- Int
frm
to :: Int
to = if Int
stride forall a. Ord a => a -> a -> Bool
>= Int
0
then forall a. Enum a => a -> Int
fromEnum (forall a. Bounded a => a
maxBound :: a)
else forall a. Enum a => a -> Int
fromEnum (forall a. Bounded a => a
minBound :: a)
in (Int
frm, Int
nxt, Int
to)
in forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum (forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall {b} {a}. (Enum b, Enum a) => (a, b) -> (Int, Int, Int)
adapt forall (m :: * -> *) a.
(Monad m, Integral a) =>
Unfold m (a, a, a) a
enumerateFromThenToIntegral)
class Enum a => Enumerable a where
enumerateFrom :: Monad m => Unfold m a a
enumerateFromTo :: Monad m => Unfold m (a, a) a
enumerateFromThen :: Monad m => Unfold m (a, a) a
enumerateFromThenTo :: Monad m => Unfold m (a, a, a) a
#define ENUMERABLE_BOUNDED_SMALL(SMALL_TYPE) \
instance Enumerable SMALL_TYPE where { \
{-# INLINE enumerateFrom #-}; \
enumerateFrom = enumerateFromSmallBounded; \
{-# INLINE enumerateFromThen #-}; \
enumerateFromThen = enumerateFromThenSmallBounded; \
{-# INLINE enumerateFromTo #-}; \
enumerateFromTo = enumerateFromToSmall; \
{-# INLINE enumerateFromThenTo #-}; \
enumerateFromThenTo = enumerateFromThenToSmall }
ENUMERABLE_BOUNDED_SMALL(())
ENUMERABLE_BOUNDED_SMALL(Bool)
ENUMERABLE_BOUNDED_SMALL(Ordering)
ENUMERABLE_BOUNDED_SMALL(Char)
#define ENUMERABLE_BOUNDED_INTEGRAL(INTEGRAL_TYPE) \
instance Enumerable INTEGRAL_TYPE where { \
{-# INLINE enumerateFrom #-}; \
enumerateFrom = enumerateFromIntegralBounded; \
{-# INLINE enumerateFromThen #-}; \
enumerateFromThen = enumerateFromThenIntegralBounded; \
{-# INLINE enumerateFromTo #-}; \
enumerateFromTo = enumerateFromToIntegralBounded; \
{-# INLINE enumerateFromThenTo #-}; \
enumerateFromThenTo = enumerateFromThenToIntegralBounded }
ENUMERABLE_BOUNDED_INTEGRAL(Int)
ENUMERABLE_BOUNDED_INTEGRAL(Int8)
ENUMERABLE_BOUNDED_INTEGRAL(Int16)
ENUMERABLE_BOUNDED_INTEGRAL(Int32)
ENUMERABLE_BOUNDED_INTEGRAL(Int64)
ENUMERABLE_BOUNDED_INTEGRAL(Word)
ENUMERABLE_BOUNDED_INTEGRAL(Word8)
ENUMERABLE_BOUNDED_INTEGRAL(Word16)
ENUMERABLE_BOUNDED_INTEGRAL(Word32)
ENUMERABLE_BOUNDED_INTEGRAL(Word64)
#define ENUMERABLE_UNBOUNDED_INTEGRAL(INTEGRAL_TYPE) \
instance Enumerable INTEGRAL_TYPE where { \
{-# INLINE enumerateFrom #-}; \
enumerateFrom = enumerateFromIntegral; \
{-# INLINE enumerateFromThen #-}; \
enumerateFromThen = enumerateFromThenIntegral; \
{-# INLINE enumerateFromTo #-}; \
enumerateFromTo = enumerateFromToIntegral; \
{-# INLINE enumerateFromThenTo #-}; \
enumerateFromThenTo = enumerateFromThenToIntegral }
ENUMERABLE_UNBOUNDED_INTEGRAL(Integer)
ENUMERABLE_UNBOUNDED_INTEGRAL(Natural)
#define ENUMERABLE_FRACTIONAL(FRACTIONAL_TYPE,CONSTRAINT) \
instance (CONSTRAINT) => Enumerable FRACTIONAL_TYPE where { \
{-# INLINE enumerateFrom #-}; \
enumerateFrom = enumerateFromFractional; \
{-# INLINE enumerateFromThen #-}; \
enumerateFromThen = enumerateFromThenFractional; \
{-# INLINE enumerateFromTo #-}; \
enumerateFromTo = enumerateFromToFractional; \
{-# INLINE enumerateFromThenTo #-}; \
enumerateFromThenTo = enumerateFromThenToFractional }
ENUMERABLE_FRACTIONAL(Float,)
ENUMERABLE_FRACTIONAL(Double,)
ENUMERABLE_FRACTIONAL((Fixed a),HasResolution a)
ENUMERABLE_FRACTIONAL((Ratio a),Integral a)
instance Enumerable a => Enumerable (Identity a) where
{-# INLINE enumerateFrom #-}
enumerateFrom :: forall (m :: * -> *). Monad m => Unfold m (Identity a) (Identity a)
enumerateFrom =
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> Unfold m a b -> Unfold m a c
map forall a. a -> Identity a
Identity forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap forall a. Identity a -> a
runIdentity forall a (m :: * -> *). (Enumerable a, Monad m) => Unfold m a a
enumerateFrom
{-# INLINE enumerateFromThen #-}
enumerateFromThen :: forall (m :: * -> *).
Monad m =>
Unfold m (Identity a, Identity a) (Identity a)
enumerateFromThen =
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> Unfold m a b -> Unfold m a c
map forall a. a -> Identity a
Identity forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall a. Identity a -> a
runIdentity forall a. Identity a -> a
runIdentity) forall a (m :: * -> *).
(Enumerable a, Monad m) =>
Unfold m (a, a) a
enumerateFromThen
{-# INLINE enumerateFromTo #-}
enumerateFromTo :: forall (m :: * -> *).
Monad m =>
Unfold m (Identity a, Identity a) (Identity a)
enumerateFromTo =
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> Unfold m a b -> Unfold m a c
map forall a. a -> Identity a
Identity forall a b. (a -> b) -> a -> b
$ forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall a. Identity a -> a
runIdentity forall a. Identity a -> a
runIdentity) forall a (m :: * -> *).
(Enumerable a, Monad m) =>
Unfold m (a, a) a
enumerateFromThen
{-# INLINE enumerateFromThenTo #-}
enumerateFromThenTo :: forall (m :: * -> *).
Monad m =>
Unfold m (Identity a, Identity a, Identity a) (Identity a)
enumerateFromThenTo =
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> Unfold m a b -> Unfold m a c
map forall a. a -> Identity a
Identity forall a b. (a -> b) -> a -> b
$
forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
lmap
(\(Identity a
from, Identity a
next, Identity a
to) ->
(forall a. Identity a -> a
runIdentity Identity a
from, forall a. Identity a -> a
runIdentity Identity a
next, forall a. Identity a -> a
runIdentity Identity a
to))
forall a (m :: * -> *).
(Enumerable a, Monad m) =>
Unfold m (a, a, a) a
enumerateFromThenTo