git.iko.soy/rowtype-yoga/purescript-yoga-tree
on master help sign in
Implement `lastChild` without intermediate Loc value
commitfe7a3580b1aa0f2c806dad6f250d2fd7682c556b authorJordan Martinez <jordanalex.martinez@gmail.com> dateSat 20 Apr 2019, 08:21 (7 years ago) parentd03ff5d
1 file changed+9−1
src/Data/Tree/Zipper.purs+9−1
src/Data/Tree/Zipper.purs+9−1
@@ -103,7 +103,15 @@ down = firstChild
103103
104104-- | Move the cursor to the last child of the current `Node`.
105105lastChild :: forall a. Loc a -> Maybe (Loc a)
106−lastChild p@(Loc r) = last <$> down p
106+lastChild n =
107+ case reverse (children n) of
108+ Nil -> Nothing
109+ c:cs ->
110+ Just $ Loc { node: c
111+ , before: cs
112+ , after: Nil
113+ , parents: n : (parents n)
114+ }
107115
108116-- | Move the cursor to a specific sibling by it's index.
109117siblingAt :: forall a. Int -> Loc a -> Maybe (Loc a)