diff --git a/bower.json b/bower.json index c38ccc2..1a7620f 100644 --- a/bower.json +++ b/bower.json @@ -12,13 +12,13 @@ "url": "git://github.com/dmbfm/purescript-tree.git" }, "dependencies": { - "purescript-prelude": "^3.1.0", - "purescript-console": "^3.0.0", - "purescript-lists": "^4.9.1", - "purescript-free": "^4.1.0" + "purescript-prelude": "^4.0.1", + "purescript-console": "^4.1.0", + "purescript-lists": "^5.0.0", + "purescript-free": "^5.1.0" }, "devDependencies": { - "purescript-psci-support": "^3.0.0", - "purescript-spec": "^1.0.0" + "purescript-psci-support": "^4.0.0", + "purescript-spec": "^3.0.0" } } diff --git a/src/Data/Tree/Zipper.purs b/src/Data/Tree/Zipper.purs index 5c1b889..041eae6 100644 --- a/src/Data/Tree/Zipper.purs +++ b/src/Data/Tree/Zipper.purs @@ -264,21 +264,24 @@ findFromRootWhere predicate loc = findDownWhere predicate $ root loc findFromRoot :: forall a. Eq a => a -> Loc a -> Maybe (Loc a) findFromRoot a = findFromRootWhere (_ == a) +-- | flattens the Tree into a List depth first. flattenLocDepthFirst :: ∀ a. Loc a -> List (Loc a) flattenLocDepthFirst loc = loc : (go loc) - where + where go :: Loc a -> List (Loc a) - go goLoc = - let - downs = goDir goLoc down - nexts = goDir goLoc next - in + go loc' = + let + downs = goDir loc' down + nexts = goDir loc' next + in downs <> nexts goDir :: Loc a -> (Loc a -> Maybe (Loc a)) -> List (Loc a) - goDir loc' dirFn = case (dirFn loc') of - Just justLoc' -> loc' : go justLoc' - Nothing -> Nil + goDir loc' dirFn = case (dirFn loc') of + Just l -> l : go l + Nothing -> Nil + + -- Setters and Getters node :: forall a. Loc a -> Tree a diff --git a/test/Main.purs b/test/Main.purs index e25cc0f..96641f0 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -3,18 +3,16 @@ module Test.Main where import Prelude import Control.Comonad.Cofree (head, (:<)) -import Control.Monad.Eff (Eff) -import Control.Monad.Aff.Console (log) import Data.List (List(Nil), (:)) import Data.Maybe (Maybe(..), fromJust) -import Data.Tree (Tree, mkTree, scanTree, showTree) +import Data.Tree (Tree, mkTree, scanTree) import Data.Tree.Zipper (down, findDownWhere, findFromRoot, findUp, flattenLocDepthFirst, fromTree, insertAfter, modifyValue, next, toTree, value) -import Debug.Trace (spy) +import Effect (Effect) import Partial.Unsafe (unsafePartial) import Test.Spec (describe, it) import Test.Spec.Assertions (shouldEqual) import Test.Spec.Reporter (consoleReporter) -import Test.Spec.Runner (RunnerEffects, run) +import Test.Spec.Runner (run) sampleTree :: Tree Int sampleTree = @@ -30,7 +28,7 @@ sampleTree = ) : Nil -main :: forall e. Eff (RunnerEffects e) Unit +main :: Effect Unit main = run [consoleReporter] do describe "Tree" do @@ -259,8 +257,8 @@ main = run [consoleReporter] do it "Should flatten the Tree into a list of locations following a depth first pattern" do let flat = map value $ flattenLocDepthFirst $ fromTree sampleTree - -- log $ showTree sampleTree - -- log $ show flat + --log $ showTree sampleTree + --log $ show flat shouldEqual flat (1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : Nil)