Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-puchitomato
A small module for a string literal type that guarantees a String value the same as its Symbol parameter.
https://github.com/justinwoo/purescript-puchitomato
purescript
Last synced: about 2 months ago
JSON representation
A small module for a string literal type that guarantees a String value the same as its Symbol parameter.
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-puchitomato
- Owner: justinwoo
- License: mit
- Created: 2018-07-19T22:35:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-19T22:36:31.000Z (over 6 years ago)
- Last Synced: 2024-10-11T22:20:06.618Z (2 months ago)
- Topics: purescript
- Language: PureScript
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Purescript-PuchiTomato
A small module for a string literal type that guarantees a `String` value the same as its `Symbol` parameter.
![](https://i.imgur.com/NkDWYEv.jpg)
## Usage
```purs
appleP = TP.SProxy :: TP.SProxy "apple"type AppleSL = PT.StringLiteral "apple"
appleSL :: AppleSL
appleSL = PT.mkStringLiteral applePmain = do
let (res1 :: JSON.E AppleSL) = JSON.readJSON "\"apple\""
assert (isRight res1)let (res2 :: JSON.E AppleSL) = JSON.readJSON "\"apples\""
assert (isLeft res2)assert (JSON.writeJSON appleSL == "\"apple\"")
assert (PT.extractString appleSL == "apple")
assert (show appleSL == "apple")
let (res4 :: Maybe AppleSL) = PT.parseStringLiteral "apple"
assert (isJust res4)let (res5 :: Maybe AppleSL) = PT.parseStringLiteral "apples"
assert (isNothing res5)
```See the [API Docs](https://pursuit.purescript.org/packages/purescript-puchitomato/) or the [tests](test/Main.purs) for usage.