Skip to content

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

Notifications You must be signed in to change notification settings

justinwoo/purescript-chahan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages