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
45import Prelude hiding (length, read)
46import Control.Monad (when)
47import Control.Monad.IO.Class (MonadIO)
48import GHC.Base (Int(..))
49import qualified GHC.Exts as Exts
51import Streamly.Streams.Serial (SerialT)
52import Streamly.Streams.StreamK.Type (IsStream)
53import Streamly.Internal.Data.Fold.Types (Fold(..))
54import Streamly.Internal.Data.Unfold.Types (Unfold(..))
55import Streamly.Internal.Data.Array (Array(..))
57import qualified Streamly.Internal.Data.Array as A
58import qualified Streamly.Streams.Prelude as P
59import qualified Streamly.Streams.StreamD as D
61{-# INLINE fromStreamN #-}
62fromStreamN :: MonadIO m => Int -> SerialT m a -> m (Array a)
64 when (n < 0) $ error "fromStreamN: negative write count specified"
65 A.fromStreamDN n $ D.toStreamD m
67{-# INLINE_EARLY toStream #-}
68toStream :: (Monad m, IsStream t) => Array a -> t m a
69toStream = D.fromStreamD . A.toStreamD
71{-# INLINE_EARLY toStreamRev #-}
72toStreamRev :: (Monad m, IsStream t) => Array a -> t m a
73toStreamRev = D.fromStreamD . A.toStreamDRev
76length :: Array a -> Int
77length Array {..} = aLen
80fold :: forall m a b . Monad m => Fold m a b -> Array a -> m b
81fold f arr = P.runFold f (toStream arr :: SerialT m a)
83{-# INLINE streamFold #-}
84streamFold :: Monad m => (SerialT m a -> m b) -> Array a -> m b
85streamFold f arr = f (toStream arr)
87{-# INLINE_NORMAL read #-}
88read :: Monad m => Unfold m (Array a) a
89read = Unfold step inject
91 inject arr = return (arr, 0)
93 | i == aLen = return D.Stop
96 case Exts.indexArray# (aA arr) i of
97 (# 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