0.2.0 • Published 3 years ago

@delveam/goethite v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

goethite

JavaScript meets Rust

Examples

Using the Option type:

import { some } from "./goethite.esm.js";

const message = some(3)
	.map((v) => v * 8)
	.map((v) => v - 3)
	.map((v) => v * 2)
	.map((v) => `The meaning of life is ${v}.`);

console.log(message.unwrapOr("For a moment, nothing happened."));

// Output: "The meaning of life is 42."

Using the Result type:

import { ok, err } from "./goethite.esm.js";

const db = new Map();

db.set(345, { name: "Lewis" });
db.set(119, { name: "Marine" });

function getUserById(id) {
	if (!db.has(id)) {
		return err("Could not find user in database.");
	}

	return ok(db.get(id));
}

const user = getUserById(345);

if (user.isOk()) {
	console.log(`${user.unwrap().name}, I found your shorts!`);
}

// Output: "Lewis, I found your shorts!"
0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago