Skip to content

thayamizu/pyroxene

Repository files navigation

pyroxene

MIT License Build Status Coverage Status Maintainability

Description

My Typescript Utility Library.

Usage

Option

Represents a option value. An instance of Option object is either a Some or None object.

import { Some, None } from "../src/Option";

//create some
const some = Some(10);

//isDefined
console.log(some.isDefined);

//isEmpty
console.log(some.isEmpty);

//getOrElse
console.log(some.getOrElse(0));

//fold
some.fold<void>(
  () => {
    //if option is empty then callback this func.
  },
  (v: number) => {
    //if option is defined then call this func.
  }
);

//map
some.map<string>((v: number) => {
  return v.toString();
});

//flatMap
some.flatMap<string>(v => {
  return Some(v.toString());
});

Either

The Either type represents values with two possibilities. A value of type Either<T, U> is either Left T type or Right U type.

import { Left, Right } from "../src/Either";

//create right
const either = Right(10);

//isLeft
console.log(either.isLeft());

//isRight
console.log(either.isRight());

//getOrElse
console.log(either.getOrElse(0));

//fold
either.fold<void>(
  () => {
    //if option is empty then callback this func.
  },
  (v: number) => {
    //if option is defined then call this func.
  }
);

//map
either.map<string>((v: number) => {
  return v.toString();
});

//flatMap
either.flatMap<string>(v => {
  return Some(v.toString());
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published