Hematite
Table of contents
- What is this?
- Why was it made?
- Where is the important stuff?
- How to use it?
- Who can contribute?
- Which license is used?
What is this?
This is an experimental Deno library to write code that more or less feel just a little bit kind of Rust-ish, while being as typed as possible.
There are a few tests and documentation comments here and there, as well as some documented undefined behaviour.
For now (and who knows for how long), everything only handles well-formed inputs.
Why was this made?
For no real reason besides testing some Typescript type shenanigans. I highly discourage you from using this library in any production work.
Where is the important stuff?
hematite
|- mod.ts ---------------- You can import important stuff from here
|- traits
|- into_iterator.ts --- IntoIterator trait wannabe
|- iterator.ts -------- Iterator trait lookalike
|- types
|- const_iterator.ts -- Iterator over pre-defined items
|- map.ts ------------- Map struct copycat
|- option.ts ---------- Option enum impersonator
|- result.ts ---------- Result enum aspirant
|- mod.ts ------------- Types entrypoint
|- utils
|- function.ts -------- Function utilities
|- tuple.ts ----------- Tuple type utilitiesHow to use it?
Itâs quite simple, reallyâŚ
Option<T>
function nullableToOption<T>(
value: T | null | undefined,
): Option<NonNullable<T>> {
if (value === null || value === undefined) {
return Option.None();
}
return Option.Some(value);
}
// Option<number>
const maybeNumber = nullableToOption(5);
if (maybeNumber.isSome()) {
console.log(maybeNumber.unwrap() * 2);
}console.log(Option.Some(5).map((n) => n * 2));Who can contribute?
Anyone who cares.
If you are actively using the library (which I wouldnât recommend) and there are some things you want to see added, fixed or whatever, feel free to open an issue. I canât guarantee that itâll be taken care of though.
If you are fixing or adding stuff and such on this library, and you want to share your amazing work with the users of this repo, consider opening a pull request.
Which license is used?
MIT License - Copyright (c) 2023 Pascal GIAMMELLUCA