Option: build, map, getOrElse
1.2× slowerShow the code
Effect's time over functype's, in each of the 5 processes: from 0.83 to 0.94.
(i) => Some(i).map(inc).getOrElse(() => 0)(i) => Option.getOrElse(Option.map(Option.some(i), inc), () => 0)Performance
10 everyday operations, each written the way its library's docs write it, timed whenever functype's code changes on main and every week. Where the two are level, or Effect is faster, this page says so.
functype main at 019d8b7 · Effect 4.1.5 · Node 24.20.0 · 2026-11-23
Effect's time over functype's, in each of the 5 processes: from 0.83 to 0.94.
(i) => Some(i).map(inc).getOrElse(() => 0)(i) => Option.getOrElse(Option.map(Option.some(i), inc), () => 0)Effect's time over functype's, in each of the 5 processes: from 1.13 to 1.32.
(i) => Right(i).map(inc).getOrElse(() => 0)(i) => Result.getOrElse(Result.map(Result.succeed(i), inc), () => 0)Effect's time over functype's, in each of the 5 processes: from 0.32 to 0.34.
(i) => List(items).map((x) => x + i).filter((x) => x % 2 === 0).size(i) => Arr.filter(Arr.map(items, (x) => x + i), (x) => x % 2 === 0).lengthEffect's time over functype's, in each of the 5 processes: from 5.58 to 6.33.
(i) => IO.succeed(i).map(inc).runSyncOrThrow()(i) => Effect.runSync(Effect.map(Effect.succeed(i), inc))Effect's time over functype's, in each of the 5 processes: from 1.57 to 1.71.
(i) => {
let io = IO.succeed(i)
for (let k = 0; k < 50; k++) io = io.flatMap((x) => IO.succeed(x + 1))
return io.runSyncOrThrow()
}(i) => {
let ef = Effect.succeed(i)
for (let k = 0; k < 50; k++) ef = Effect.flatMap(ef, (x) => Effect.succeed(x + 1))
return Effect.runSync(ef)
}Effect's time over functype's, in each of the 5 processes: from 0.99 to 1.07.
(i) =>
IO.gen(function* () {
let x = i
for (let k = 0; k < 10; k++) x = yield* IO.succeed(x + 1)
return x
}).runSyncOrThrow()(i) =>
Effect.runSync(
Effect.gen(function* () {
let x = i
for (let k = 0; k < 10; k++) x = yield* Effect.succeed(x + 1)
return x
}),
)Effect's time over functype's, in each of the 5 processes: from 4.69 to 5.06.
(i) =>
IO.fail(new Boom())
.catchTag("Boom", () => IO.succeed(i))
.runSyncOrThrow()(i) => Effect.runSync(Effect.catchTag(Effect.fail(new Boom()), "Boom", () => Effect.succeed(i)))Effect's time over functype's, in each of the 5 processes: from 2.29 to 2.36.
(i) =>
IO.service(DbF)
.map((d) => d.k + i)
.provideService(DbF, db)
.runSyncOrThrow()(i) =>
Effect.runSync(
Effect.provideService(
Effect.map(DbE, (d) => d.k + i),
DbE,
db,
),
)Effect's time over functype's, in each of the 5 processes: from 1.42 to 1.55.
(i) =>
IO.async(() => Promise.resolve(i))
.map(inc)
.runOrThrow()(i) =>
Effect.runPromise(
Effect.map(
Effect.promise(() => Promise.resolve(i)),
inc,
),
)Effect's time over functype's, in each of the 5 processes: from 1.22 to 1.28.
(i) => {
let io = IO.succeed(i)
for (let k = 0; k < 50; k++) io = io.flatMap((x) => IO.succeed(x + 1))
return io.runOrThrow()
}(i) => {
let ef = Effect.succeed(i)
for (let k = 0; k < 50; k++) ef = Effect.flatMap(ef, (x) => Effect.succeed(x + 1))
return Effect.runPromise(ef)
}The same small program in each library, bundled by esbuild for the browser, minified, then gzipped.
import { Option } from "functype"
console.log(Option(1).map((x) => x + 1).getOrElse(() => 0))import { Option } from "effect"
console.log(Option.getOrElse(Option.map(Option.some(1), (x) => x + 1), () => 0))import { IO, Either, Option, List } from "functype"
const p = IO.gen(function* () { const a = yield* IO.succeed(1); return a + 1 }).catchTag("X", () => IO.succeed(0))
console.log(p.runSyncOrThrow(), Either.right(1).map((x) => x), Option(1), List([1]).map((x) => x))import { Effect, Result, Option, Array as Arr } from "effect"
const p = Effect.catchTag(Effect.gen(function* () { const a = yield* Effect.succeed(1); return a + 1 }), "X", () => Effect.succeed(0))
console.log(Effect.runSync(p), Result.map(Result.succeed(1), (x) => x), Option.some(1), Arr.map([1], (x) => x))const inc = (x) => x + 1
const items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
class Boom { _tag = "Boom" }
const DbF = Tag("Db") // functype
class DbE extends Context.Service()("Db") {} // Effect
const db = { k: 3 }pnpm install
pnpm -F functype build
pnpm -F functype-bench benchThe cases are in packages/bench/src/cases.mjs. A case that's unfair to either library is a bug: open an issue.