case package:data-diverse

This class allows defining handlers that can handle the Head type in the xs typelist. In conjunction with Reiterate, you can define handlers that can handle all the types in the xs typelist. See Data.Diverse.CaseFunc and Data.Diverse.Cases.
Return the handler/continuation when x is observed.
This handler stores a polymorphic function that returns a different type.
let y = pick (5 :: Int) :: Which '[Int, Bool]
switch y (CaseFunc @Typeable (show . typeRep . (pure @Proxy))) `shouldBe` Int
let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nul
afoldr (:) [] (forMany (CaseFunc @Typeable (show . typeRep . (pure @Proxy))) x) `shouldBe`
["Int", "Bool", "Char", "Maybe Char", "Int", "Maybe Char"]
This handler stores a polymorphic function that doesn't change the type.
let x = (5 :: Int) ./ (6 :: Int8) ./ (7 :: Int16) ./ (8 :: Int32) ./ nil
y = (15 :: Int) ./ (16 :: Int8) ./ (17 :: Int16) ./ (18 :: Int32) ./ nil
afmap (CaseFunc' @Num (+10)) x `shouldBe` y
This handler stores a polymorphic function that work on higher kinds, eg Functor You may want to use C0 for k@
A varation of CaseFunc1 that doesn't change the return type
This handler stores a polymorphic function which maps containers to continuations. This is especially useful for building Cases using afmap.
A variant of CaseIxedCont with more constraints.
A variant of CaseIxedCont1_ for which the type of both containers is fixed.
A variant of CaseIxedCont for which the type of both containers is fixed.
>>> let ps = Predicate @Int (> 5) ./ Predicate isLetter ./ Predicate id ./ nil
>>> let ps' = cases $ afmap (CaseIxedCont_ @C0 getPredicate) ps
>>> switch (pick @Int @'[Int, Bool, Char] 5) ps' :: Bool
False
>>> switch (pick @Char @'[Int, Bool, Char] 6) ps' :: Bool
True
>>> switch (pick @Char @'[Int, Bool, Char] '_') ps' :: Bool
False
>>> switch (pick @Int @'[Int, Bool, Char] 'a') ps' :: Bool
True
>>> switch (pick @Bool @'[Int, Bool, Char] False) ps' :: Bool
False
>>> switch (pick @Bool @'[Int, Bool, Char] True) ps' :: Bool
True
This handler stores a polymorphic function which changes the type of the containers.
>>> let f (x :: f a) = Const @String @a $ show x
>>> let xs = (Just @Int 5) ./ Right @Int False ./ "X" ./ (Left @Int @Bool 6) ./ nil
>>> afmap (CasedIxedFunc @Show f) xs :: Many '[Const String Int, Const String Bool, Const String Char, Const String Bool]
Const "Just 5" ./ Const "Right False" ./ Const "\"X\"" ./ Const "Left 6" ./ nil
>>> atraverse (CasedIxedFunc @Show f) xs :: Const String (Many '[Int, Bool, Char, Bool])
Const "Just 5Right False\"X\"Left 6"