Realised listify should return a list, and added depth-first and breadth-first versions
This commit is contained in:
parent
b6176ee615
commit
01fff6e617
|
@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
module Data.Generics.Polyplate.Schemes where
|
module Data.Generics.Polyplate.Schemes where
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
|
|
||||||
import Data.Generics.Polyplate
|
import Data.Generics.Polyplate
|
||||||
|
@ -73,15 +74,16 @@ applyQuery2 qfA qfB = makeRecurseQ ops
|
||||||
where
|
where
|
||||||
ops = baseOp `extOpQ` qfA `extOpQ` qfB
|
ops = baseOp `extOpQ` qfA `extOpQ` qfB
|
||||||
|
|
||||||
applyListify :: PolyplateSpine t (OneOpQ (Maybe s) s) () (Maybe s) => (s -> Bool) -> t -> Tree (Maybe s)
|
applyListifyDepth :: PolyplateSpine t (OneOpQ (Maybe s) s) () (Maybe s) => (s -> Bool) -> t -> [s]
|
||||||
applyListify qf = fmap joinMaybe . makeRecurseQ ops
|
applyListifyDepth qf = catMaybes . flatten . fmap (fromMaybe Nothing) . makeRecurseQ ops
|
||||||
where
|
where
|
||||||
qf' x = if qf x then Just x else Nothing
|
qf' x = if qf x then Just x else Nothing
|
||||||
|
ops = baseOp `extOpQ` qf'
|
||||||
|
|
||||||
joinMaybe :: Maybe (Maybe a) -> Maybe a
|
applyListifyBreadth :: PolyplateSpine t (OneOpQ (Maybe s) s) () (Maybe s) => (s -> Bool) -> t -> [s]
|
||||||
joinMaybe Nothing = Nothing
|
applyListifyBreadth qf = catMaybes . (concat . levels) . fmap (fromMaybe Nothing) . makeRecurseQ ops
|
||||||
joinMaybe (Just mx) = mx
|
where
|
||||||
|
qf' x = if qf x then Just x else Nothing
|
||||||
ops = baseOp `extOpQ` qf'
|
ops = baseOp `extOpQ` qf'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user