git.iko.soy/rowtype-yoga/purescript-yoga-tree
on master help sign in
Implement `lastChild` without intermediate Loc value
fe7a358Jordan Martinez
src/Data/Tree/Zipper.purs+9−1
@@ -103,7 +103,15 @@ down = firstChild
103
103
104-- | Move the cursor to the last child of the current `Node`.
104-- | Move the cursor to the last child of the current `Node`.
105lastChild :: forall a. Loc a -> Maybe (Loc a)
105lastChild :: 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+ }
107
115
108-- | Move the cursor to a specific sibling by it's index.
116-- | Move the cursor to a specific sibling by it's index.
109siblingAt :: forall a. Int -> Loc a -> Maybe (Loc a)
117siblingAt :: forall a. Int -> Loc a -> Maybe (Loc a)