Skip to content

Instantly share code, notes, and snippets.

@saml
Created January 9, 2013 22:21
Show Gist options
  • Save saml/4497545 to your computer and use it in GitHub Desktop.
Save saml/4497545 to your computer and use it in GitHub Desktop.
lends stuff
import Control.Lens
import Control.Monad.State
import Data.Foldable (mapM_)
data Rec =
Rec { _recA :: Int, _recB :: String, _recC :: Double }
deriving (Eq, Ord, Show)
makeLenses Rec
a = Just 1
b = Nothing
c = Just 3.14
x = Rec 0 "" 0.0
-- I want to update x with a, b, c and skip Nothing.
main = do
let x' = flip execState x $ do
mapM_ (assign recA) a
mapM_ (assign recB) b
mapM_ (assign recC) c
print x'
-- http://hpaste.org/80514#a80515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment