From caac354759a62a52596b6f77971327e17ff81c0f Mon Sep 17 00:00:00 2001 From: Zoe Stafford Date: Sat, 12 Nov 2022 10:09:15 +0000 Subject: [PATCH] Add some missing functions for `Biplate` --- src/Data/Uniplate.idr | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Data/Uniplate.idr b/src/Data/Uniplate.idr index f85a677..1750717 100644 --- a/src/Data/Uniplate.idr +++ b/src/Data/Uniplate.idr @@ -210,6 +210,21 @@ public export transformM : Uniplate ty => Monad m => (ty -> m ty) -> ty -> m ty transformM f = assert_total (descendM (transformM f)) >=> f +||| Get all children of a node, including non-direct descendents. +public export +biuniverse : Biplate from to => from -> List to +biuniverse x = foldMap universe (biplate x).cs + +||| Apply a function to each sub-node of the target type +public export +bitransform : Biplate from to => (to -> to) -> from -> from +bitransform f = bidescend (transform f) + +||| Apply a monadic function to each sub-node of the target type +public export +bitransformM : Biplate from to => Monad m => (to -> m to) -> from -> m from +bitransformM f = bidescendM (transformM f) + ||| Find the fixed point of a function applied to every sub-node of a node ||| This ensures there is nowhere in the node that can have the function applied ||| ie forall f, x. all (isNothing . f) (universe (fixpoint f x)) = True