upgraded to purescript 0.12

This commit is contained in:
Dustin Whitney 2018-06-18 23:26:56 -04:00
parent 591a7d4f58
commit c242a176e4
3 changed files with 24 additions and 23 deletions

View File

@ -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"
}
}

View File

@ -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

View File

@ -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)