summaryrefslogtreecommitdiff
path: root/examples/example0.1/Example0_1.hs
blob: 517921fb80ff986a0e5f1b6b692bdea871009641 (plain)
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
28
29
30
31
32
33
34
35
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 ()