Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.16 KB

README.md

File metadata and controls

57 lines (45 loc) · 1.16 KB

PureScript-Chahan

Turn your Generics-Rep Sums and Products into lists, because that's cool.

Usage

See <test/Main.purs>

class SumNames (list :: SumList1) where
  sumNames :: SLProxy list -> NonEmptyList String

-- ...

data Fruit
  = Apple
  | Banana
  | Cherry
derive instance genericFruit :: Generic Fruit _

availableFruits
  :: forall rep list
   . Generic Fruit rep
  => SumToList rep list
  => SumNames list
  => NonEmptyList String
availableFruits = sumNames (SLProxy :: SLProxy list)

data Thing
  = Thing Int String Int
derive instance genericThing :: Generic Thing _

thingNames
  :: forall rep name list
   . Generic Thing rep
  => ToProductList rep name list
  => IsSymbol name
  => ProductNames list
  => NonEmptyList String
thingNames =
  head <> productNames (PLProxy :: PLProxy list)
  where
    head = pure $ reflectSymbol (SProxy :: SProxy name)

-- ...
    test "SumToList works" do
      Assert.equal
        "Apple, Banana, Cherry"
        (intercalate ", " availableFruits)

    test "ToProductList/ProductToList works" do
      Assert.equal
        "Thing Int String Int"
        (intercalate " " thingNames)