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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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]


Change log CHANGES.md
Dependencies base (>=4.7 && <5), fused-effects (>=0.1.2 && <1), lens (>=4 && <5) [details]
License BSD-3-Clause
Copyright 2018 Patrick Thomson
Author Patrick Thomson
Maintainer patrickt@github.com
Category Web
Home page https://github.com/patrickt/fused-effects-lens#readme
Uploaded by patrick_thomson at 2019-01-09T18:56:04Z


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for fused-effects-lens-

[back to package description]


This package provides an interface to the lens library that is compatible with fused-effects. The standards 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)


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 :: (Member (State Context) sig, Carrier sig m, Monad m) => m Int
stateTest = do
  initial <- use amount
  assign amount (initial + 1)
  assign disabled True
  use amount

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


BSD3, like fused-effects.