-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement set for isTuple * Add default impl: isChild(isParent) => true * Implement list interfaces for isListOf * Add RegExp * Update README.md
- Loading branch information
Showing
7 changed files
with
384 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,26 +30,26 @@ PredScript is an attempt to make a flexible dependently-typed functional languag | |
with familiar (easy / mainstream / JS-like) syntax that lies | ||
somewhere on the spectrum of `Dynamically Typed → Statically Typed`. | ||
|
||
## Use Case | ||
## Code Example | ||
|
||
```typescript | ||
let isUser: isPred = gen_isRecord({ | ||
interface isEmailString extends isString; | ||
function isEmailString(s: isString): isBool { | ||
/^\S+@\S+\.\S+$/ | ||
.test($this, s) | ||
} | ||
|
||
let isUser: isPred = gen_isRecord({ | ||
"id": isInt, | ||
"username": isString | ||
"username": isString, | ||
"email": isEmailString | ||
}); | ||
|
||
// this can be type checked at compile time | ||
async function fetchUserById(id: isInt): isUser { | ||
(baseURL + "/users/" + id) | ||
.fetch | ||
.await | ||
.get($this, "body") | ||
.parseJSON | ||
// validate and cast at runtime | ||
.as(isUser, $this) | ||
} | ||
|
||
fetchUserById(5).then($this, println); | ||
let u: isUser = as(isUser, { | ||
"id": 1, | ||
"username": "johndoe", | ||
"email": "[email protected]" | ||
}); | ||
``` | ||
## Design goals | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.