2{-# LANGUAGE MagicHash #-}
3{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE UnboxedTuples #-}
11-- Module : Streamly.Data.Array
12-- Copyright : (c) 2019 Composewell Technologies
14-- License : BSD-3-Clause
15-- Maintainer : streamly@composewell.com
16-- Stability : experimental
19module Streamly.Data.Array
50import Prelude hiding (length, read)
51import Control.Monad (when)
52import Control.Monad.IO.Class (MonadIO)
53import GHC.Base (Int(..))
54import qualified GHC.Exts as Exts
56import Streamly.Streams.Serial (SerialT)
57import Streamly.Streams.StreamK.Type (IsStream)
58import Streamly.Internal.Data.Fold.Types (Fold(..))
59import Streamly.Internal.Data.Unfold.Types (Unfold(..))
60import Streamly.Internal.Data.Array (Array(..))
62import qualified Streamly.Internal.Data.Array as A
63import qualified Streamly.Streams.Prelude as P
64import qualified Streamly.Streams.StreamD as D
66{-# INLINE fromStreamN #-}
67fromStreamN :: MonadIO m => Int -> SerialT m a -> m (Array a)
69 when (n < 0) $ error "fromStreamN: negative write count specified"
70 A.fromStreamDN n $ D.toStreamD m
72{-# INLINE fromStream #-}
73fromStream :: MonadIO m => SerialT m a -> m (Array a)
74fromStream m = A.fromStreamD $ D.toStreamD m
76{-# INLINE_EARLY toStream #-}
77toStream :: (Monad m, IsStream t) => Array a -> t m a
78toStream = D.fromStreamD . A.toStreamD
80{-# INLINE_EARLY toStreamRev #-}
81toStreamRev :: (Monad m, IsStream t) => Array a -> t m a
82toStreamRev = D.fromStreamD . A.toStreamDRev
85fold :: forall m a b . Monad m => Fold m a b -> Array a -> m b
86fold f arr = P.runFold f (toStream arr :: SerialT m a)
88{-# INLINE streamFold #-}
89streamFold :: Monad m => (SerialT m a -> m b) -> Array a -> m b
90streamFold f arr = f (toStream arr)
92{-# INLINE_NORMAL read #-}
93read :: Monad m => Unfold m (Array a) a
94read = Unfold step inject
96 inject arr = return (arr, 0)
98 | i == A.length arr = return D.Stop
101 case Exts.indexArray# (array# arr) i of
102 (# x #) -> D.Yield x (arr, I# i + 1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list