Functype

Scala-Inspired Functional Programming for TypeScript

Type-safe, immutable, and composable data structures with unified interfaces

import { Option, Either } from "functype"

// Handle null safety with Option
const user = Option(maybeUser)
  .map(u => u.name)
  .getOrElse("Guest")

// Elegant error handling with Either
const result = Either
  .fromTry(() => JSON.parse(data))
  .map(obj => obj.value)
12x
Faster List Operations
Tree-Shakeable
Optimized Bundle Size
100%
TypeScript

Why Functype?

A functional programming library designed for TypeScript developers who value type safety and composition

Scala-Style API

Familiar constructor functions with method chaining. Works like Scala's collections API.

High Performance

Do-notation is 12x faster for List comprehensions compared to traditional flatMap chains.

Unified Interfaces

All types implement the same hierarchy of interfaces. Learn once, use everywhere.

Tree-Shakeable

Import only what you need. Optimized for minimal bundle size with selective imports.

Core Data Structures

Option<T>

Safe handling of nullable values with Some and None

Either<L,R>

Express success/failure with Left and Right values

List<A>

Immutable arrays with functional operations

Task<T>

Async operations with cancellation and error handling

Do-notation

Scala-like for-comprehensions for monadic composition

Match/Cond

Powerful pattern matching and conditional expressions

Quick Start

Get up and running with functype in minutes

1

Install functype

npm install functype

Also works with yarn, pnpm, and bun

2

Import what you need

import { Option, Either, List } from "functype"

// Or use selective imports for smaller bundles
import { Option } from "functype/option"
3

Start coding functionally

const result = Option(user)
  .map(u => u.email)
  .filter(email => email.includes("@"))
  .getOrElse("no-email@example.com")