Skip to content

Commit

Permalink
Add some missing functions for Biplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-snails committed Nov 12, 2022
1 parent ae2afc5 commit caac354
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Data/Uniplate.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit caac354

Please sign in to comment.