summaryrefslogtreecommitdiff
path: root/examples/example0.1/Example0_1.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example0.1/Example0_1.hs')
-rw-r--r--examples/example0.1/Example0_1.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/example0.1/Example0_1.hs b/examples/example0.1/Example0_1.hs
new file mode 100644
index 0000000..517921f
--- /dev/null
+++ b/examples/example0.1/Example0_1.hs
@@ -0,0 +1,36 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE Arrows #-}
+
+import Data.DocRecord
+import qualified Data.Text.Lazy as T
+import Porcupine
+import Prelude hiding (id, (.))
+
+
+yzCompress :: T.Text -> T.Text
+yzCompress = T.concat . map counts . T.group
+ where
+ counts s = T.pack (show (T.length s)) <> T.take 1 s <> ","
+
+resultFile :: DataSink T.Text
+resultFile = dataSink ["result"] $
+ somePureSerial (PlainTextSerial (Just "txt"))
+ <> lmap yzCompress
+ (somePureSerial (PlainTextSerial (Just "yz")))
+
+myTask :: (LogThrow m) => PTask m () ()
+myTask = proc () -> do
+ (FV chars :& FV nums :& _) <-
+ getOptions ["options"]
+ ( docField @"chars" "a" "The chars to repeat"
+ :& docField @"replications" [10::Int] "The numbers of replications"
+ :& RNil) -< ()
+ let txt = T.concat $
+ zipWith (\s n -> T.replicate (fromIntegral n) (T.singleton s)) chars nums
+ writeData resultFile -< txt
+
+main :: IO ()
+main = runLocalPipelineTask (FullConfig "example0.1" "example0_1.yaml" "." ()) myTask ()