pred-trie 0.0.6.1 → 0.0.7
raw patch · 3 files changed
+27/−18 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Trie.Pred.Unified: getFirst :: [Maybe a] -> Maybe a
Files
pred-trie.cabal view
@@ -1,5 +1,5 @@ Name: pred-trie-Version: 0.0.6.1+Version: 0.0.7 Author: Athan Clark <athan.clark@gmail.com> Maintainer: Athan Clark <athan.clark@gmail.com> License: BSD3
src/Data/Trie/Pred/Unified.hs view
@@ -1,8 +1,16 @@-module Data.Trie.Pred.Unified where+module Data.Trie.Pred.Unified+ ( RUPTrie (..)+ , merge+ , lookup+ , lookupNearestParent+ , litSingleton+ , litExtrude+ ) where -import Data.Trie.Pred.Unified.Tail+import Prelude hiding (lookup)+import Data.Trie.Pred.Unified.Tail hiding (lookup, lookupNearestParent, merge) import qualified Data.Trie.Pred.Unified.Tail as NU-import Data.Monoid hiding (getFirst)+import Data.Monoid import qualified Data.List.NonEmpty as NE @@ -23,16 +31,17 @@ lookup :: (Eq t) => [t] -> RUPTrie t x -> Maybe x lookup [] (Rooted mx _) = mx-lookup ts (Rooted _ xs) = getFirst $ map (NU.lookup $ NE.fromList ts) xs+lookup ts (Rooted _ xs) = firstJust $ map (NU.lookup $ NE.fromList ts) xs lookupNearestParent :: (Eq t) => [t] -> RUPTrie t x -> Maybe x lookupNearestParent [] (Rooted mx _) = mx-lookupNearestParent ts (Rooted mx xs) = getFirst $ map (NU.lookupNearestParent $ NE.fromList ts) xs+lookupNearestParent ts (Rooted mx xs) =+ getFirst $ (First $ firstJust $ map (NU.lookupNearestParent $ NE.fromList ts) xs) <> (First mx) -getFirst :: [Maybe a] -> Maybe a-getFirst [] = Nothing-getFirst (Nothing:xs) = getFirst xs-getFirst (Just x :xs) = Just x+firstJust :: [Maybe a] -> Maybe a+firstJust [] = Nothing+firstJust (Nothing:xs) = firstJust xs+firstJust (Just x :xs) = Just x litSingleton :: [t] -> x -> RUPTrie t x litSingleton [] x = Rooted (Just x) []
src/Data/Trie/Pred/Unified/Tail.hs view
@@ -58,13 +58,13 @@ lookup (t:|ts) (UMore t' mx xs) | t == t' = case ts of [] -> mx- _ -> getFirst $ map (lookup $ NE.fromList ts) xs+ _ -> firstJust $ map (lookup $ NE.fromList ts) xs | otherwise = Nothing lookup (t:|ts) (UPred _ p mrx xrs) = p t >>= \r -> case ts of [] -> ($ r) <$> mrx- _ -> ($ r) <$> (getFirst $ map (lookup $ NE.fromList ts) xrs)+ _ -> ($ r) <$> (firstJust $ map (lookup $ NE.fromList ts) xrs) lookupNearestParent :: Eq t => NonEmpty t -> UPTrie t x -> Maybe x@@ -72,7 +72,7 @@ Nothing -> if t == t' then case ts of [] -> mx -- redundant; should have successful lookup- _ -> case getFirst $ map (lookupNearestParent $ NE.fromList ts) xs of+ _ -> case firstJust $ map (lookupNearestParent $ NE.fromList ts) xs of Nothing -> mx justr -> justr else Nothing@@ -81,17 +81,17 @@ Nothing -> p t >>= \r -> case ts of [] -> ($ r) <$> mrx -- redundant; should have successful lookup- _ -> case getFirst $ map (lookupNearestParent $ NE.fromList ts) xrs of+ _ -> case firstJust $ map (lookupNearestParent $ NE.fromList ts) xrs of Nothing -> ($ r) <$> mrx justr -> ($ r) <$> justr justr -> justr -getFirst :: [Maybe a] -> Maybe a-getFirst [] = Nothing-getFirst (Nothing:xs) = getFirst xs-getFirst (Just x :xs) = Just x+firstJust :: [Maybe a] -> Maybe a+firstJust [] = Nothing+firstJust (Nothing:xs) = firstJust xs+firstJust (Just x :xs) = Just x litSingletonTail :: NonEmpty t -> x -> UPTrie t x