[Fencommits] fenserve: simplify code
Benja Fallenstein
benja.fallenstein at gmail.com
Sun Apr 29 17:47:02 EEST 2007
Sun Apr 29 17:46:53 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* simplify code
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-04-29 17:47:02.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-04-29 17:47:02.000000000 +0300
@@ -5,7 +5,7 @@
import Data.Generics (Typeable)
import Data.Binary hiding (get,put)
import Data.Char
-import Data.List (intersperse, isPrefixOf)
+import Data.List (intersperse, isPrefixOf, inits)
import Data.Maybe (fromMaybe)
import Text.Printf
import System.Time
@@ -50,11 +50,8 @@
Nothing -> respond $ "Path not found: " ++ renderPath path
-- get the path of the closest ancestor that is its own page
-getPage p note = fromMaybe [] $ g p note where
- f [] _ = Nothing
- f (i:is) cs | i < 0 || i >= length cs = Nothing
- | otherwise = fmap (i:) $ g is (cs !! i)
- g p (Note _ o cs) = f p cs `mplus` (if o then Just [] else Nothing)
+getPage p note = last $ filter isOwnPage $ inits p where
+ isOwnPage q = case getPath q note of Just (Note _ o _) -> o; _ -> False
getPath [] note = Just note
getPath (i:is) (Note _ _ cs) | i >= 0 && i < length cs = getPath is (cs !! i)
More information about the Fencommits
mailing list