HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Moduleeither-n-0.1.0.0Haskell2010

Data.Lens.Injection.Injection2

The second injection of a sum type, as a prism. The sum-type dual of Control.Lens.Field2.

  • 1 class
  • Packageeither-n-0.1.0.0
  • Exports1
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInjection2.hs
classclass Injection2 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Access the second constructor of a sum type.

Where Control.Lens._2 is the second projection out of a product, _I2 is the second injection into a sum.

The default implementation is the prism to the second constructor of a Generic type, injection (Proxy :: Proxy 1).

Example3 expressions
data T = C1 | C2 Int | C3 deriving (Show, Generic)instance Injection2 T T Int IntC2 1 ^? _I2Just 1
Example1 expression
C3 ^? _I2Nothing
Example1 expression
_I2 # 1 :: TC2 1

Methods

Instances9Injection2, …
  • Injection2 Bool Bool () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    True ^? _I2Just ()
    Example1 expression
    False ^? _I2Nothing
    Example1 expression
    _I2 # () :: BoolTrue
  • Injection2 Ordering Ordering () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    EQ ^? _I2Just ()
    Example1 expression
    LT ^? _I2Nothing
    Example1 expression
    GT ^? _I2Nothing
    Example1 expression
    _I2 # () :: OrderingEQ
  • Injection2 (Maybe a) (Maybe b) a bDefined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    Just 1 ^? _I2Just 1
    Example1 expression
    (Nothing :: Maybe Int) ^? _I2Nothing
    Example1 expression
    _I2 # 1 :: Maybe IntJust 1
    Example1 expression
    over _I2 show (Just 1)Just "1"
  • Injection2 [a] [b] (NonEmpty a) (NonEmpty b)Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2

    A list is the sum of the empty list and a non-empty list.

    Example1 expression
    [1, 2, 3] ^? _I2Just (1 :| [2,3])
    Example1 expression
    ([] :: [Int]) ^? _I2Nothing
    Example1 expression
    _I2 # (1 :| [2, 3]) :: [Int][1,2,3]
    Example1 expression
    over _I2 (fmap show) [1, 2, 3]["1","2","3"]
  • Injection2 (Either c a) (Either c b) a bDefined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    (Right "x" :: Either Int String) ^? _I2Just "x"
    Example1 expression
    (Left 1 :: Either Int String) ^? _I2Nothing
    Example1 expression
    _I2 # "x" :: Either Int StringRight "x"
    Example1 expression
    over _I2 show (Right True :: Either Int Bool)Right "True"
  • Injection2 (Either3 a b c) (Either3 a b' c) b b'Defined in either-n-0.1.0.0 · Data.Either3.Either3
    Example1 expression
    (Second3 True :: Either3 Int Bool String) ^? _I2Just True
    Example1 expression
    _I2 # True :: Either3 Int Bool StringSecond3 True
  • Injection2 (Either3T Identity a b c) (Either3T Identity a b' c) b b'Defined in either-n-0.1.0.0 · Data.Either3.Either3T
    Example1 expression
    e3 (Second3 True) ^? _I2Just True
  • Injection2 (Sum f g a) (Sum f g' a) (g a) (g' a)Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    (InR [1] :: Sum Maybe [] Int) ^? _I2Just [1]
    Example1 expression
    (InL (Just 1) :: Sum Maybe [] Int) ^? _I2Nothing
    Example1 expression
    _I2 # [1] :: Sum Maybe [] IntInR [1]
  • Injection2 ((:+:) f g p) ((:+:) f g' p) (g p) (g' p)Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection2
    Example1 expression
    (R1 [1] :: (Maybe :+: []) Int) ^? _I2Just [1]
    Example1 expression
    (L1 (Just 1) :: (Maybe :+: []) Int) ^? _I2Nothing
    Example1 expression
    _I2 # [1] :: (Maybe :+: []) IntR1 [1]