Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-shoronpo
A library for type-level Symbol formatting with other Symbols, e.g. intercalated record labels
https://github.com/justinwoo/purescript-shoronpo
formatting purescript symbols type-level
Last synced: about 2 months ago
JSON representation
A library for type-level Symbol formatting with other Symbols, e.g. intercalated record labels
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-shoronpo
- Owner: justinwoo
- License: mit
- Created: 2018-05-29T21:16:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T13:10:24.000Z (about 3 years ago)
- Last Synced: 2024-10-11T23:44:39.524Z (2 months ago)
- Topics: formatting, purescript, symbols, type-level
- Language: PureScript
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PureScript-Shoronpo
A library for type-level Symbol formatting with other Symbols, e.g. intercalated record labels.
![](https://i.imgur.com/EtAGHnK.jpg)
Who doesn't love shoronpo/xiaolongbao?
You might want to use this together with [Jajanmen](https://github.com/justinwoo/purescript-jajanmen) for amazing results (example to be made, but imagine you had a record for select query results and wanted to use its labels in your query template).
## Usage
Define as separate terms or use inline:
```purs
type MyRecord =
{ a :: Int
, b :: String
, c :: Unit
}-- inferred type:
labels :: SProxy "a, b, c"
labels =
S.intercalateRecordLabels
(Proxy :: Proxy MyRecord)
(SProxy :: SProxy ", ")-- inferred type:
formatted :: SProxy "my labels: a, b, c"
formatted =
S.formatSymbol
(SProxy :: SProxy "my labels: {labels}")
{ labels }
```Then put it to work:
```purs
main :: Effect Unit
main = do
let
myLabels =
S.intercalateRecordLabels
(Proxy :: Proxy { apple :: Int, banana :: String })
(SProxy :: SProxy ", ")
myFormatted =
S.formatSymbol
(SProxy :: SProxy "myLabels: {myLabels}")
{ myLabels }assertEqual
{ actual: reflectSymbol myFormatted
, expected: "myLabels: apple, banana"
}
log $ reflectSymbol myLabels
log $ reflectSymbol myFormatted
```