ekmett / ekmett/bound

Add predicate to substitute functions

Open
#90 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
130
Forks
30
PR merge metrics
No merged PRs in 30d

Description

```haskell
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
```

```haskell
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.