git.iko.soy/rowtype-yoga/purescript-yoga-tree
on master help sign in
upgraded to purescript 0.12
commitc242a176e49385cd5c05b0a08811780c4492bc7c authorDustin Whitney <dustin.whitney@gmail.com> dateMon 18 Jun 2018, 23:26 (8 years ago) parent591a7d4
3 files changed+24−23
bower.json+6−6 src/Data/Tree/Zipper.purs+12−9 test/Main.purs+6−8
bower.json+6−6
@@ -12,13 +12,13 @@
1212 "url": "git://github.com/dmbfm/purescript-tree.git"
1313 },
1414 "dependencies": {
15− "purescript-prelude": "^3.1.0",
16− "purescript-console": "^3.0.0",
17− "purescript-lists": "^4.9.1",
18− "purescript-free": "^4.1.0"
15+ "purescript-prelude": "^4.0.1",
16+ "purescript-console": "^4.1.0",
17+ "purescript-lists": "^5.0.0",
18+ "purescript-free": "^5.1.0"
1919 },
2020 "devDependencies": {
21− "purescript-psci-support": "^3.0.0",
22− "purescript-spec": "^1.0.0"
21+ "purescript-psci-support": "^4.0.0",
22+ "purescript-spec": "^3.0.0"
2323 }
2424}
src/Data/Tree/Zipper.purs+12−9
@@ -264,21 +264,24 @@ findFromRootWhere predicate loc = findDownWhere predicate $ root loc
264264findFromRoot :: forall a. Eq a => a -> Loc a -> Maybe (Loc a)
265265findFromRoot a = findFromRootWhere (_ == a)
266266
267+-- | flattens the Tree into a List depth first.
267268flattenLocDepthFirst :: ∀ a. Loc a -> List (Loc a)
268269flattenLocDepthFirst loc = loc : (go loc)
269− where
270+ where
270271 go :: Loc a -> List (Loc a)
271− go goLoc =
272− let
273− downs = goDir goLoc down
274− nexts = goDir goLoc next
275− in
272+ go loc' =
273+ let
274+ downs = goDir loc' down
275+ nexts = goDir loc' next
276+ in
276277 downs <> nexts
277278
278279 goDir :: Loc a -> (Loc a -> Maybe (Loc a)) -> List (Loc a)
279− goDir loc' dirFn = case (dirFn loc') of
280− Just justLoc' -> loc' : go justLoc'
281− Nothing -> Nil
280+ goDir loc' dirFn = case (dirFn loc') of
281+ Just l -> l : go l
282+ Nothing -> Nil
283+
284+
282285
283286-- Setters and Getters
284287node :: forall a. Loc a -> Tree a
test/Main.purs+6−8
@@ -3,18 +3,16 @@ module Test.Main where
33import Prelude
44
55import Control.Comonad.Cofree (head, (:<))
6−import Control.Monad.Eff (Eff)
7−import Control.Monad.Aff.Console (log)
86import Data.List (List(Nil), (:))
97import Data.Maybe (Maybe(..), fromJust)
10−import Data.Tree (Tree, mkTree, scanTree, showTree)
8+import Data.Tree (Tree, mkTree, scanTree)
119import Data.Tree.Zipper (down, findDownWhere, findFromRoot, findUp, flattenLocDepthFirst, fromTree, insertAfter, modifyValue, next, toTree, value)
12−import Debug.Trace (spy)
10+import Effect (Effect)
1311import Partial.Unsafe (unsafePartial)
1412import Test.Spec (describe, it)
1513import Test.Spec.Assertions (shouldEqual)
1614import Test.Spec.Reporter (consoleReporter)
17−import Test.Spec.Runner (RunnerEffects, run)
15+import Test.Spec.Runner (run)
1816
1917sampleTree :: Tree Int
2018sampleTree =
@@ -30,7 +28,7 @@ sampleTree =
3028 )
3129 : Nil
3230
33−main :: forall e. Eff (RunnerEffects e) Unit
31+main :: Effect Unit
3432main = run [consoleReporter] do
3533 describe "Tree" do
3634
@@ -259,8 +257,8 @@ main = run [consoleReporter] do
259257
260258 it "Should flatten the Tree into a list of locations following a depth first pattern" do
261259 let flat = map value $ flattenLocDepthFirst $ fromTree sampleTree
262− -- log $ showTree sampleTree
263− -- log $ show flat
260+ --log $ showTree sampleTree
261+ --log $ show flat
264262 shouldEqual flat (1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : Nil)
265263
266264