我有下面的代碼:Haskell Pipes:如何對生產者的輸出進行排序?
import Control.Monad (unless)
import Pipes
import qualified Pipes.Prelude as P
import System.FilePath.Posix ((</>))
import System.Posix.Directory (DirStream, openDirStream, readDirStream)
produceFiles :: DirStream -> Producer FilePath IO()
produceFiles ds = do
path <- lift $ readDirStream ds
yield path
unless (path == "") $ produceFiles ds
getDC :: FilePath -> Producer FilePath IO()
getDC top = do
ds <- lift $ openDirStream top
produceFiles ds
runTest top = runEffect $ getDC top >-> P.map (top</>) >-> P.stdoutLn
它打印目錄top
的所有文件。在打印之前如何對輸出進行排序?我是否需要編寫一個消費者,將輸出「排走」到列表中,然後對其進行排序?我正在使用管道-4.1.4。