Skip to content

Instantly share code, notes, and snippets.

@fragamus
Last active April 30, 2017 00:19
Show Gist options
  • Save fragamus/6a54eb38952aaeefdf32a5e0636cec11 to your computer and use it in GitHub Desktop.
Save fragamus/6a54eb38952aaeefdf32a5e0636cec11 to your computer and use it in GitHub Desktop.
the counter handled by stateT isn't changing with modify (+1)
#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (FilePath)
import Turtle
import Control.Monad.State
import Data.Text
import Filesystem.Path.CurrentOS
import Data.Either
import Data.Either.Utils
main = view $ ((flip runStateT) 0) $ filePathProducer baseDirectory
baseDirectory = Filesystem.Path.CurrentOS.fromText "."
filePathProducer path = do
child <- lift $ lstree path
modify (+1)
i <- get
if (i `mod` 3 == 0)
then (lift . echo) "**********************************"
else (lift . echo . Data.Text.pack . show) i
(lift . echo . fromRight . toText) child
@fragamus
Copy link
Author

sample output:

[1 of 1] Compiling Main ( ../ii.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
1
./a1
((),1)
1
./a2
((),1)
1
./a3
((),1)
1
./a4
((),1)
1
./a5
((),1)
1
./a6
((),1)
1
./b/b1
((),1)
1
./b/b2
((),1)
1
./b/b3
((),1)
1
./b/b4
((),1)
1
./b/b5
((),1)
1
./b/b6
((),1)
1
./b/c/c1
((),1)
1
./b/c/c2
((),1)
1
./b/c/c3
((),1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment