fused-effects-lens: Monadic lens combinators for fused-effects.

[ bsd3, control, library ] [ Propose Tags ]

Provides combinators for the lens-based manipulation of state and context types provided by the fused-effects library, similar to those provided for mtl-based monad transformers.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0, 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.2.0.1
Change log CHANGES.md
Dependencies base (>=4.7 && <5), fused-effects (>=1.0 && <1.1), microlens (>=0.4 && <1) [details]
License BSD-3-Clause
Copyright 2018-2019 Patrick Thomson
Author Patrick Thomson
Maintainer patrickt@github.com
Category Control
Home page https://github.com/fused-effects/fused-effects-lens#readme
Source repo head: git clone https://github.com/fused-effects/fused-effects-lens
Uploaded by patrick_thomson at 2020-01-04T14:07:37Z
Distributions NixOS:1.2.0.1
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2865 total (37 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for fused-effects-lens-1.2.0.0

[back to package description]

fused-effects-lens

Hackage BSD3 license Build Status

This package provides an interface to the lens library (and other such libraries such as microlens and generic-lens) that is compatible with fused-effects. The standard formulation of lens combinators for operating in MonadState contexts—use, .=, et al—rely on mtl for MonadState and MonadReader, which is not applicable to Reader and State effects.

This package is meant to be used alongside lens, like so:

import Control.Lens hiding (view, use, assign)
import Control.Effect.Lens (view, use, assign)

Example

Given a Context type that we will use in a State effect:

data Context = Context
  { _amount :: Int
  , _disabled :: Bool
  } deriving (Eq, Show)

makeLenses ''Context

We can can use the use combinators to extract a lens target from the current state, and assign to write to a field of that state:

stateTest :: (Has (State Context) sig m) => m Int
stateTest = do
  initial <- use amount
  amount .= (initial + 1)
  disabled .= True
  use amount

You can find a more complete example, including one that works with multiple State constraints in a single computation, in the test directory.

License

BSD3, like fused-effects.