Skip to content

Commit

Permalink
Reimplement missing functions from microlens-0.2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fmthoma committed Jan 25, 2021
1 parent 0347a9b commit 6fc8db1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Control/Lens/Compat.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -fno-warn-dodgy-imports #-}
module Control.Lens.Compat
( pre
, assign
, modifying
, traverseOf

, Getter

, module Lens.Micro.Platform
) where

import Data.Monoid (First)
import Lens.Micro.Platform
import Lens.Micro.Platform hiding (assign, modifying, traverseOf)
import Control.Monad.State (MonadState, modify)


pre :: Getting (First a) s a -> Getter s (Maybe a)
pre l = to (preview l)
{-# INLINE pre #-}

assign :: MonadState s m => ASetter s s a b -> b -> m ()
assign l b = modify (set l b)
{-# INLINE assign #-}

modifying :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
modifying l f = modify (over l f)
{-# INLINE modifying #-}

traverseOf :: a -> a
traverseOf = id
{-# INLINE traverseOf #-}

type Getter s a = SimpleGetter s a

Expand Down

0 comments on commit 6fc8db1

Please sign in to comment.