X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.db%2Fscl%2FSimantics%2FDB.scl;h=02396067875b83abb5c4fc25e44b4841bb7e47e6;hp=ac50e3e73525dab3bd2f5afb71c59a0ab97800ed;hb=bb1507f2eaee879439d355bf6b052e16d0df1bff;hpb=12468c2b3d87f61123d6429a7329d80316009fe6 diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index ac50e3e73..023960678 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -455,4 +455,28 @@ lift2Write f x y = syncWrite (\_ -> f x y) @inline lift3Write :: (a -> b -> c -> d) -> (a -> b -> c -> d) -lift3Write f x y z = syncWrite (\_ -> f x y z) \ No newline at end of file +lift3Write f x y z = syncWrite (\_ -> f x y z) + +""" +Returns a child Browsable of the specified parent that has that is the child +of the specified parent with the specified name path. +""" +childWithPath :: Browsable a => a -> [String] -> a +childWithPath parent path = + foldl (\r name -> match possibleChild r name with + Just c -> c + Nothing -> fail ("Didn't find " + name + ".") + ) + parent path + +""" +Like `childWithPath` but returns Maybe a which will be `Nothing` if no child +was found. +""" +possibleChildWithPath :: Browsable a => a -> [String] -> Maybe a +possibleChildWithPath parent path = + foldl (\r name -> match r with + Just c -> possibleChild c name + Nothing -> Nothing + ) + (Just parent) path