edit: A monad for rewriting things.

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Edit is a monad for rewriting things.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
no_arbitrary

Removes QuickCheck as a dependency (so no Arbitrary instance is provided).

Disabled
no_comonad

Removes comonad as a dependency (so no Comonad instance is provided).

Disabled
tutorial

Build the tutorial. Adds dependencies on uniplate and containers.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0, 0.0.1.1, 1.0.0.0, 1.0.1.0
Change log ChangeLog.md
Dependencies base (>=4.9 && <4.12), comonad, deepseq (>=1.1 && <1.5), QuickCheck (>=2.10 && <2.13), transformers (>=0.5 && <0.6) [details]
License BSD-3-Clause
Copyright Varun Gandhi 2018
Author Varun Gandhi <theindigamer15@gmail.com>
Maintainer Varun Gandhi <theindigamer15@gmail.com>
Category Data
Home page https://github.com/theindigamer/edit
Source repo head: git clone https://github.com/theindigamer/edit.git
Uploaded by theindigamer at 2018-09-03T14:16:10Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2232 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-09-03 [all 1 reports]

Readme for edit-1.0.1.0

[back to package description]

Edit Hackage badge Stackage badge

The Edit monad allows you to easily bubble up whether a change was made or not when rewriting things. Some cases where this can be handy:

  1. You are making a sequence of transformations on some type and want to keep track of whether any of them changed it or not.
  2. You are rewriting a recursive type (or a garden of mutually recursive types!) and want to bubble up information whether something was changed or not.

For example, Reddit user /u/p__bing says

[..] I work as an iOS developer and we have this same exact idea implemented, as a monad, in Swift, to make our UI updates faster (if a change goes through our model layer and comes out Clean, we don’t bother touching the UI).

A small example:

>>> halveEvens x = if x `mod` 2 == 0 then (Dirty $ x `div` 2) else (Clean x)
>>> traverse halveEvens [1, 2, 3]
Dirty [1,1,3]
>>> traverse halveEvens [1, 3, 5]
Clean [1,3,5]

More thorough documentation is available on Hackage under the Data.Edit module. There is a tutorial too under Data.Edit.Tutorial.

There is also a corresponding monad transformer EditT available under Control.Monad.Trans.EditT.

Contributing

Please open an issue on the Github issue tracker to discuss missing documentation, API changes etc.