Skip to content

Add predicate to substitute functions #90

@Icelandjack

Description

@Icelandjack
substitute :: Monad f => Eq a => a -> f a -> f a -> f a
substitute = substituteOf . (==)

substituteBy :: Monad m => (a -> Bool) -> m a -> m a -> m a
substituteBy old new as = do
  a <- as
  if old a
    then new
    else pure a
substituteVar :: Functor f => Eq a => a -> a -> f a -> f a
substituteVar = substituteVarOf . (==)

substituteVarBy :: Functor f => (a -> Bool) -> a -> f a -> f a
substituteVarBy old new as = do
  a <- as
  pure
    if old a
      then new
      else a

Is there a use for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions