{-# LANGUAGE OverloadedStrings #-} import Control.Lens test3s = [Left (1::Int), Left (2::Int),Right 3] test3_3 :: Maybe [Either Int Int] test3_3 = case preview (_head . _Left) test3s of Just _ -> Just (set (_head . _Left) 200 test3s) Nothing -> Nothing data MaybeMatched a = Matched a | NotMatched a deriving (Show,Functor) instance Applicative MaybeMatched where pure a = NotMatched a NotMatched a <*> NotMatched b = NotMatched $ a b NotMatched a <*> Matched b = Matched $ a b Matched a <*> NotMatched b = Matched $ a b Matched a <*> Matched b = Matched $ a b test_mm :: MaybeMatched [Either Int Int] test_mm = let myset lens x = lens (\_ -> Matched x) in myset (_head . _Left) 5 test3s -- try replacing with [] main = print test_mm