Skip to content
📚Write cleaner Typescript
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
scripts
src
test
.editorconfig feat: initial commit Aug 8, 2018
.gitignore
.node-version
.nvmrc
LICENSE
README.md
circle.yml chore: upgrade project dependencies (#105) Jul 24, 2019
codecov.yml
package-lock.json
package.json
tsconfig.build.json fix: correct build compilation failure (#28) Oct 5, 2018
tsconfig.json fix: correct build compilation failure (#28) Oct 5, 2018
tslint.json

README.md

📚 typescript-monads

Better TypeScript Control Flow

circeci codeclimate

greenkeeper greenkeeper greenkeeper

semantic-release npm latest version

typescript-monads helps you write safer code by using abstractions over messy control flow and state.

Installation

You can use this library in the browser, node, or a bundler

Node or as a module

npm install typescript-monads

Browser

<head>
 <script src="https://unpkg.com/typescript-monads"></script>
 <!-- or use a specific version to avoid a redirect --> 
 <script src="https://unpkg.com/typescript-monads@3.8.0/index.min.js"></script>
</head>
var someRemoteValue;
typescriptMonads.maybe(someRemoteValue).tapSome(console.log)

Example Usage

Maybe

import { maybe } from 'typescript-monads'

// safely map values
let maybeVisitedBeforeXTimes: number | undefined = 50

const priceWithDiscountForLoyalty = maybe(maybeVisitedBeforeXTimes)
  .match({
    some: visits => 15.00 - visits * 0.1,
    none: () => 15.00
  })

// handle multiple maybe conditionas together
const canRideCoaster = getAge() // Maybe<number>
  .bind(age => getTicket(age)) // Maybe<Ticket>
  .match({
    some: ticket => ticket.canRide('coaster1'),
    none: () => false
  })

// operations with side-effects
maybe(process.env.DB_URL)
  .do({
    some: dbUrl => {
      // value exists, can connect
    },
    none: () => console.info('no url provided, could not connect to the database')
  })

Either

TODO

Reader

TODO

Result

TODO

You can’t perform that action at this time.