Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/justinwoo/purescript-chahan

Turn your Generics-Rep Sums and Products into lists, because that's cool.
https://github.com/justinwoo/purescript-chahan

generics-rep purescript type-level

Last synced: 15 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# PureScript-Chahan

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

![](https://i.imgur.com/xd77crJ.jpg)

## Usage

See

```hs
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)
```