data-diverse-lens-1.0.0.1: Isos & Lens for Data.Diverse.Many and Prisms for Data.Diverse.Which

Safe HaskellNone
LanguageHaskell2010

Data.Diverse.Lens.Which

Contents

Synopsis

Single type

Prism

class AsFacet a s where Source #

pick (review facet) and trial (preview facet) in Prism' form.

facet = prism' pick (trial')
let y = review (facet @Int) (5 :: Int) :: Which '[Bool, Int, Char, Bool, Char] -- pick
    x = preview (facet @Int) y -- trial
x `shouldBe` (Just 5)

Methods

facet :: Prism' s a Source #

Make it easy to create an instance of AsFacet using Typed

facet :: AsType a s => Prism' s a Source #

Make it easy to create an instance of AsFacet using Typed

Instances

UniqueMember * x xs => AsFacet x (Which xs) Source # 

Methods

facet :: Prism' (Which xs) x Source #

class AsFacetL l a s | s l -> a where Source #

pickL (review facetL) and trialL' (preview facetL') in Prism' form.

let y = review (facetL @Bar Proxy) (Tagged (5 :: Int)) :: Which '[Tagged Foo Bool, Tagged Bar Int, Char, Bool, Char]
    x = preview (facetL @Bar Proxy) y
x `shouldBe` (Just (Tagged 5))

Minimal complete definition

facetL

Methods

facetL :: Prism' s a Source #

Instances

(UniqueLabelMember * k l xs, (~) * x (KindAtLabel * k l xs)) => AsFacetL k l x (Which xs) Source # 

Methods

facetL :: Prism' s (Which xs) Source #

class AsFacetTag l a s | s l -> a where Source #

Variation of fetchL specialized to Tagged which automatically tags and untags the field. A default implementation using generics is not provided as it make GHC think that l must be type Symbol when l can actually be any kind. Create instances of AsFacetTag' using Data.Generics.Sum.Constructors as follows: instance AsConstructor' l Foo Foo a a => AsFacetTag l a Foo where facetTag = _Ctor l @

Minimal complete definition

facetTag

Methods

facetTag :: Prism' s a Source #

Instances

(UniqueLabelMember * k l xs, (~) * (Tagged k l x) (KindAtLabel * k l xs)) => AsFacetTag k l x (Which xs) Source # 

Methods

facetTag :: Prism' s (Which xs) Source #

class AsFacetN n a s | s n -> a where Source #

pickN (review facetN) and trialN (preview facetN) in Prism' form.

facetN p = prism' (pickN p) (trialN' p)
let y = review (facetN (Proxy @4)) (5 :: Int) :: Which '[Bool, Int, Char, Bool, Int, Char] -- pickN
    x = preview (facetN (Proxy @4)) y -- trialN
x `shouldBe` (Just 5)

Minimal complete definition

facetN

Methods

facetN :: Prism' s a Source #

Instances

MemberAt * n x xs => AsFacetN n x (Which xs) Source # 

Methods

facetN :: Prism' (Which xs) x Source #

Multiple types

Prism

class AsInject as ss a s | a -> as, s -> ss, s as -> a, a ss -> s where Source #

diversify (review inject) and reinterpret' (preview inject) in Prism' form.

let x = pick (5 :: Int) :: Which '[String, Int]
    y = review (inject @_ @[Bool, Int, Char, String]) x -- diversify
y `shouldBe` pick (5 :: Int) :: Which '[Bool, Int, Char, String]
let y' = preview (inject @[String, Int]) y -- reinterpret
y' `shouldBe` Just (pick (5 :: Int)) :: Maybe (Which '[String, Int])

Minimal complete definition

inject

Methods

inject :: Prism' s a Source #

Instances

(Diversify branch tree, Reinterpret' branch tree) => AsInject [Type] branch tree (Which branch) (Which tree) Source # 

Methods

inject :: Prism' s (Which tree) Source #

class AsInjectL ls as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ls -> as where Source #

diversifyL (review injectL) and reinterpretL' (preview injectL) in Prism' form.

let t = pick @[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] (5 :: Tagged Bar Int)
    b = pick @'[Tagged Foo Bool, Tagged Bar Int] (5 :: Tagged Bar Int)
    t' = review (injectL @[Foo, Bar] @_ @[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] Proxy) b
    b' = preview (injectL @[Foo, Bar] Proxy) t'
t `shouldBe` t'
b' `shouldBe` Just b

Minimal complete definition

injectL

Methods

injectL :: Prism' s a Source #

Instances

(Diversify branch tree, Reinterpret' branch tree, (~) [Type] branch (KindsAtLabels Type k ls tree), UniqueLabels Type k ls tree, IsDistinct k ls) => AsInjectL [Type] [k] ls branch tree (Which branch) (Which tree) Source # 

Methods

injectL :: Prism' s a Source #

class AsInjectN ns as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ns -> as where Source #

diversifyN (review injectN) and reinterpretN' (preview injectN) in Prism' form.

let x = pick (5 :: Int) :: Which '[String, Int]
    y = review (injectN @[3, 1] @_ @[Bool, Int, Char, String] Proxy) x -- diversifyN
y `shouldBe` pick (5 :: Int) :: Which '[Bool, Int, Char, String]
let y' = preview (injectN @[3, 1] @[String, Int] Proxy) y -- reinterpertN'
y' `shouldBe` Just (pick (5 :: Int)) :: Maybe (Which '[String, Int])

Minimal complete definition

injectN

Methods

injectN :: Prism' s a Source #

Instances

(DiversifyN ns branch tree, ReinterpretN' ns branch tree) => AsInjectN [Type] ns branch tree (Which branch) (Which tree) Source # 

Methods

injectN :: Prism' s (Which tree) Source #