Skip to content

Instantly share code, notes, and snippets.

@jship
Created May 10, 2019 15:36
Show Gist options
  • Save jship/666303a718e531390195f73ee9be4b93 to your computer and use it in GitHub Desktop.
Save jship/666303a718e531390195f73ee9be4b93 to your computer and use it in GitHub Desktop.
printTree :: Show a => Tree a -> IO ()
printTree = putStrLn . Tree.drawTree . fmap show
tree :: Tree Int
tree = Tree.unfoldTree buildNode 1 where
buildNode :: Int -> (Int, [Int])
buildNode n
| 2 * n + 1 <= 7 = (n, [2 * n, 2 * n + 1])
| otherwise = (n, [])
zipTest = zipper tree
& downward root
& focus .~ 42
& rezip
zipTest' = zipper tree
& downward branches
& fromWithin traverse
& downward root
& rezip
tape = zipper tree
& downward branches
& fromWithin traverse
& downward root
& saveTape
tape' = zipper tree
& downward root
& saveTape
tapeTest :: IO (Tree Int)
tapeTest = do
t <- restoreTape tape tree
pure $ t
& focus .~ 99
& rezip
tapeTest' :: IO (Tree Int)
tapeTest' = do
t <- restoreTape tape' tree
pure $ t
& focus .~ 42
& rezip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment