Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-chahan
- Owner: justinwoo
- Created: 2018-04-18T21:27:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-21T14:55:07.000Z (over 6 years ago)
- Last Synced: 2024-11-14T02:14:25.108Z (about 2 months ago)
- Topics: generics-rep, purescript, type-level
- Language: PureScript
- Homepage:
- Size: 1.95 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)
```