-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVector.hs
More file actions
27 lines (22 loc) · 788 Bytes
/
Vector.hs
File metadata and controls
27 lines (22 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE FlexibleContexts #-}
import Streamly.Data.Stream (Stream)
import qualified Streamly.Data.Stream as Stream
import qualified Data.Vector.Fusion.Stream.Monadic as Vector
-- | vector to streamly
fromVector :: Monad m => Vector.Stream m a -> Stream m a
fromVector = Stream.unfoldrM unconsV
where
unconsV v = do
r <- Vector.null v
if r
then return Nothing
else do
h <- Vector.head v
return $ Just (h, Vector.tail v)
-- | streamly to vector
toVector :: Monad m => Stream m a -> Vector.Stream m a
toVector = Vector.unfoldrM Stream.uncons
main :: IO ()
main = do
Stream.toList (fromVector (Vector.fromList ([1..3]::[Int]))) >>= print
Vector.toList (toVector (Stream.fromList ([1..3]::[Int]))) >>= print