switch package:data-diverse

A switch/case statement for Which. This is equivalent to flip which Use Case instances like Cases to apply a Which of functions to a variant of values.
let y = pick (5 :: Int) :: Which '[Int, Bool]
switch y (
cases (show @Bool
./ show @Int
./ nil)) `shouldBe` "5"
Or CaseFunc @Typeable to apply a polymorphic function that work on all Typeables.
let y = pick (5 :: Int) :: Which '[Int, Bool]
switch y (CaseFunc @Typeable (show . typeRep . (pure @Proxy))) `shouldBe` Int
Or you may use your own custom instance of Case.
A friendlier constraint synonym for reinterpretN.
A switch/case statement for Which. This is equivalent to flip whichN Use Case instances like CasesN to apply a Which of functions to a variant of values in index order.
let y = pickN @0 (5 :: Int) :: Which '[Int, Bool, Bool, Int]
switchN y (
casesN (show @Int
./ show @Bool
./ show @Bool
./ show @Int
./ nil)) `shouldBe` "5"
Or you may use your own custom instance of Case.
Switcher is an instance of Reduce for which reiterates through the possibilities in a Which, delegating handling to Case, ensuring termination when Which only contains one type.
SwitcherN is a variation of Switcher which reiterateNs through the possibilities in a Which, delegating work to CaseN, ensuring termination when Which only contains one type.