https://github.com/web-pacotes/foundation-types
Curated package with types I believe all packages and apps need to promote safeness and reduced side effects.
https://github.com/web-pacotes/foundation-types
functional-programming monads types typesafe typescript
Last synced: 3 months ago
JSON representation
Curated package with types I believe all packages and apps need to promote safeness and reduced side effects.
- Host: GitHub
- URL: https://github.com/web-pacotes/foundation-types
- Owner: web-pacotes
- License: mit
- Created: 2024-04-13T09:51:11.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T16:02:16.000Z (almost 2 years ago)
- Last Synced: 2024-06-07T15:50:52.452Z (almost 2 years ago)
- Topics: functional-programming, monads, types, typesafe, typescript
- Language: TypeScript
- Homepage: https://web-pacotes.github.io/foundation-types/
- Size: 274 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# foundation-types
Curated package with types I believe all packages and apps need to promote safeness and reduced side effects.
  
---
## How to use
The following is an example how to use the `Either` monad type to eliminate exceptions thrown from a division operation:
```typescript
import { fold, Left, Right } from './either';
function div_numbers(x: number, y: number) {
if (y === 0.0) {
return Left('cannot divide number by 0!');
}
return Right(x / y);
}
const computation = div_numbers(2, 0);
fold(
computation,
(l) => console.error(l),
(r) => console.info(`division = ${r}`)
);
```
## Features
- Option type (either a value is present or absent)
- Either type (either a value or other value)
- Lazy type (lazily computed value)
- Error type (type safe errors)
- IO (Read/Write) error type
- Unknown error type
- Wrapping/Unwrapping typed error in internal errors
- Wrapper around try/catch to execute callbacks in a safe throwable environment
### Upcoming features
New types come as I need them or as requested through an issue.
---
## Bugs and Contributions
Found any bug (including typos) in the package? Do you have any suggestion
or feature to include for future releases? Please create an issue via
GitHub in order to track each contribution. Also, pull requests are very
welcome!
To contribute, start by setting up your local development environment. The [setup.md](setup.md) document will onboard
you on how to do so!