Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OsPath and write out arrays to stdout #66

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions examples/ListDir.hs
Original file line number Diff line number Diff line change
@@ -1,36 +1,75 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -ddump-simpl -dsuppress-all -ddump-to-file #-}


module Main (main) where

import Data.Maybe (fromJust)
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
-- import System.OsPath (osp)

import qualified Streamly.Data.Fold as Fold
import qualified Streamly.Internal.Data.Array as Array
import qualified Streamly.Internal.Data.Fold as Fold
import qualified Streamly.Data.Stream.Prelude as Stream
-- import qualified Streamly.Internal.Data.Stream as Stream
-- import qualified Streamly.Internal.Data.Unfold as Unfold (either, nil)
import qualified Streamly.Internal.Data.Stream as Stream
import qualified Streamly.Internal.Data.Unfold as Unfold
import qualified Streamly.Internal.FileSystem.Dir as Dir
import qualified Streamly.Internal.FileSystem.Posix.ReadDir as Dir
import qualified Streamly.Internal.FileSystem.Handle as Handle
import qualified Streamly.Internal.FileSystem.Path as Path

-- | List the current directory recursively using concurrent processing
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
Stream.fold (Fold.drainMapM print)
-- Stream.fold (Fold.drain)
-- Stream.fold (Fold.drainMapM print)
Stream.fold (Handle.writeWith 32000 stdout)
-- Stream.fold (Handle.writeChunks stdout)
-- Stream.fold (Array.lPinnedCompactGE 32000 (Handle.writeChunks stdout))
$ Array.interposeSuffix 10 -- Array.reader
-- $ Array.compactInterposeGE 10 32000
-- $ Array.pinnedCompactLE 32000
$ fmap Path.toChunk
-- $ Stream.trace (print . Path.toString)
$ Stream.unfoldMany Unfold.fromList
-- $ fmap (either id id)
$ Stream.catRights
-- $ fmap Path.toChunk
-- $ Stream.catLefts

-- Serial using unfolds (fastest serial)
-- $ Stream.unfoldIterateDfs unfoldOne
-- $ Stream.unfoldIterateBfs unfoldOne
-- $ Stream.unfoldIterateBfsRev unfoldOne

-- Serial using streams
-- $ Stream.concatIterateDfs streamOneMaybe
-- $ Stream.concatIterateBfs streamOneMaybe
-- $ Stream.concatIterateBfsRev streamOneMaybe

-- Serial using stream append and interleave
-- $ Stream.concatIterateWith Stream.append streamOne
-- $ Stream.mergeIterateWith Stream.interleave streamOne
$ Stream.parConcatIterate id streamOne

-- Concurrent
-- XXX To reduce concurrency overhead, perform buffering in each worker
-- and post the buffer or return [Path] and then unfold it.
$ Stream.parConcatIterate
-- ( Stream.eager False . Stream.maxBuffer 1000 . Stream.maxThreads 4)
id
streamOne
-- $ Stream.parConcatIterate (Stream.interleaved True) streamOne
-- $ Stream.parConcatIterate (Stream.ordered True) streamOne
$ Stream.fromPure (Left ".")
$ Stream.fromPure (Left [fromJust $ Path.fromString "."])
-- $ Stream.fromPure (Left ".")
-- $ Stream.fromPure (Left [osp|.|])

where

-- unfoldOne = Unfold.either Dir.eitherReaderPaths Unfold.nil
-- streamOneMaybe = either (Just . Dir.readEitherPaths) (const Nothing)
streamOne = either Dir.readEitherPaths (const Stream.nil)
-- streamOne = either Dir.readEitherByteChunks (const Stream.nil)
streamOne = either Dir.readEitherChunks (const Stream.nil)
6 changes: 4 additions & 2 deletions streamly-examples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ flag interop

common exe-dependencies
build-depends:
streamly == 0.10.0
, streamly-core == 0.2.0
streamly >= 0.11.0 && < 0.11.1
, streamly-core >= 0.3.0 && < 0.3.1
, base >= 4.9 && < 4.20
, directory >= 1.2 && < 1.4
, transformers >= 0.4 && < 0.7
Expand All @@ -74,6 +74,8 @@ common exe-dependencies
, unordered-containers >= 0.2 && < 0.3
, vector >= 0.12 && < 0.14
, mtl >= 2.2 && < 3
, filepath
, os-string

common exe-options
import: exe-dependencies
Expand Down