@effect/typeclass

中文文档
0.41.0发布于 2026/07/13MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 101.9万

A collection of reusable typeclasses for the Effect ecosystem

原始使用文档
文档目录26 节
  1. Members and derived functions
  2. Bounded
  3. Monoid
  4. Semigroup
  5. Members and derived functions
  6. Alternative
  7. Applicative
  8. Bicovariant
  9. Chainable
  10. Contravariant
  11. Coproduct
  12. Covariant
  13. Filterable
  14. FlatMap
  15. Foldable
  16. Invariant
  17. Monad
  18. Of
  19. Pointed
  20. Product
  21. SemiAlternative
  22. SemiApplicative
  23. SemiCoproduct
  24. SemiProduct
  25. Traversable
  26. TraversableFilterable

Introduction

Welcome to the documentation for @effect/typeclass, a collection of re-usable typeclasses for the Effect ecosystem.

The functional abstractions in @effect/typeclass can be broadly divided into two categories.

  • Abstractions For Concrete Types - These abstractions define properties of concrete types, such as number and string, as well as ways of combining those values.
  • Abstractions For Parameterized Types - These abstractions define properties of parameterized types such as ReadonlyArray and Option and ways of combining them.

Concrete Types

Members and derived functions

Note: members are in bold.

Bounded

A type class used to name the lower limit and the upper limit of a type.

Extends:

  • Order
NameGivenTo
maxBoundA
minBoundA
reverseBounded<A>Bounded<A>
clampAA

Monoid

A Monoid is a Semigroup with an identity. A Monoid is a specialization of a Semigroup, so its operation must be associative. Additionally, x |> combine(empty) == empty |> combine(x) == x. For example, if we have Monoid<String>, with combine as string concatenation, then empty = "".

Extends:

  • Semigroup
NameGivenTo
emptyA
combineAllIterable<A>A
reverseMonoid<A>Monoid<A>
tuple[Monoid<A>, Monoid<B>, ...]Monoid<[A, B, ...]>
struct{ a: Monoid<A>, b: Monoid<B>, ... }Monoid<{ a: A, b: B, ... }>
minBounded<A>Monoid<A>
maxBounded<A>Monoid<A>

Semigroup

A Semigroup is any set A with an associative operation (combine):

x |> combine(y) |> combine(z) == x |> combine(y |> combine(z))

NameGivenTo
combineA, AA
combineManyA, Iterable<A>A
reverseSemigroup<A>Semigroup<A>
tuple[Semigroup<A>, Semigroup<B>, ...]Semigroup<[A, B, ...]>
struct{ a: Semigroup<A>, b: Semigroup<B>, ... }Semigroup<{ a: A, b: B, ... }>
minOrder<A>Semigroup<A>
maxOrder<A>Semigroup<A>
constantASemigroup<A>
intercalateA, Semigroup<A>Semigroup<A>
firstSemigroup<A>
lastSemigroup<A>

Parameterized Types

Parameterized Types Hierarchy

flowchart TD
    Alternative --> SemiAlternative
    Alternative --> Coproduct
    Applicative --> Product
    Coproduct --> SemiCoproduct
    SemiAlternative --> Covariant
    SemiAlternative --> SemiCoproduct
    SemiApplicative --> SemiProduct
    SemiApplicative --> Covariant
    Applicative --> SemiApplicative
    Chainable --> FlatMap
    Chainable ---> Covariant
    Monad --> FlatMap
    Monad --> Pointed
    Pointed --> Of
    Pointed --> Covariant
    Product --> SemiProduct
    Product --> Of
    SemiProduct --> Invariant
    Covariant --> Invariant
    SemiCoproduct --> Invariant

Members and derived functions

Note: members are in bold.

Alternative

Extends:

  • SemiAlternative
  • Coproduct

Applicative

Extends:

  • SemiApplicative
  • Product
NameGivenTo
liftMonoidMonoid<A>Monoid<F<A>>

Bicovariant

A type class of types which give rise to two independent, covariant functors.

NameGivenTo
bimapF<E1, A>, E1 => E2, A => BF<E2, B>
mapLeftF<E1, A>, E1 => E2F<E2, A>
mapF<A>, A => BF<B>

Chainable

Extends:

  • FlatMap
  • Covariant
NameGivenTo
tapF<A>, A => F<B>F<A>
andThenDiscardF<A>, F<B>F<A>
bindF<A>, name: string, A => F<B>F<A & { [name]: B }>

Contravariant

Contravariant functors.

Extends:

  • Invariant
NameGivenTo
contramapF<A>, B => AF<B>
contramapCompositionF<G<A>>, A => BF<G<B>>
imapcontramapimap

Coproduct

Coproduct is a universal monoid which operates on kinds.

This type class is useful when its type parameter F<_> has a structure that can be combined for any particular type, and which also has a "zero" representation. Thus, Coproduct is like a Monoid for kinds (i.e. parametrized types).

A Coproduct<F> can produce a Monoid<F<A>> for any type A.

Here's how to distinguish Monoid and Coproduct:

  • Monoid<A> allows A values to be combined, and also means there is an "empty" A value that functions as an identity.

  • Coproduct<F> allows two F<A> values to be combined, for any A. It also means that for any A, there is an "zero" F<A> value. The combination operation and zero value just depend on the structure of F, but not on the structure of A.

Extends:

  • SemiCoproduct
NameGivenTo
zeroF<A>
coproductAllIterable<F<A>>F<A>
getMonoidMonoid<F<A>>

Covariant

Covariant functors.

Extends:

  • Invariant
NameGivenTo
mapF<A>, A => BF<B>
mapCompositionF<G<A>>, A => BF<G<B>>
imapmapimap
flapA, F<A => B>F<B>
asF<A>, BF<B>
asUnitF<A>F<void>

Filterable

Filterable<F> allows you to map and filter out elements simultaneously.

NameGivenTo
partitionMapF<A>, A => Either<B, C>[F<B>, F<C>]
filterMapF<A>, A => Option<B>F<B>
compactF<Option<A>>F<A>
separateF<Either<A, B>>[F<A>, F<B>]
filterF<A>, A => booleanF<A>
partitionF<A>, A => boolean[F<A>, F<A>]
partitionMapCompositionF<G<A>>, A => Either<B, C>[F<G<B>>, F<G<C>>]
filterMapCompositionF<G<A>>, A => Option<B>F<G<B>>

FlatMap

NameGivenTo
flatMapF<A>, A => F<B>F<B>
flattenF<F<A>>F<A>
andThenF<A>, F<B>F<B>
composeKleisliArrowA => F<B>, B => F<C>A => F<C>

Foldable

Data structures that can be folded to a summary value.

In the case of a collection (such as ReadonlyArray), these methods will fold together (combine) the values contained in the collection to produce a single result. Most collection types have reduce methods, which will usually be used by the associated Foldable<F> instance.

NameGivenTo
reduceF<A>, B, (B, A) => BB
reduceCompositionF<G<A>>, B, (B, A) => BB
reduceRightF<A>, B, (B, A) => BB
foldMapF<A>, Monoid<M>, A => MM
toReadonlyArrayF<A>ReadonlyArray<A>
toReadonlyArrayWithF<A>, A => BReadonlyArray<B>
reduceKindMonad<G>, F<A>, B, (B, A) => G<B>G<B>
reduceRightKindMonad<G>, F<A>, B, (B, A) => G<B>G<B>
foldMapKindCoproduct<G>, F<A>, (A) => G<B>G<B>

Invariant

Invariant functors.

NameGivenTo
imapF<A>, A => B, B => AF<B>
imapCompositionF<G<A>>, A => B, B => AF<G<B>>
bindToF<A>, name: stringF<{ [name]: A }>
tupledF<A>F<[A]>

Monad

Allows composition of dependent effectful functions.

Extends:

  • FlatMap
  • Pointed

Of

NameGivenTo
ofAF<A>
ofCompositionAF<G<A>>
unitF<void>
DoF<{}>

Pointed

Extends:

  • Covariant
  • Of

Product

Extends:

  • SemiProduct
  • Of
NameGivenTo
productAllIterable<F<A>>F<ReadonlyArray<A>>
tuple[F<A>, F<B>, ...]F<[A, B, ...]>
struct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>

SemiAlternative

Extends:

  • SemiCoproduct
  • Covariant

SemiApplicative

Extends:

  • SemiProduct
  • Covariant
NameGivenTo
liftSemigroupSemigroup<A>Semigroup<F<A>>
apF<A => B>, F<A>F<B>
andThenDiscardF<A>, F<B>F<A>
andThenF<A>, F<B>F<B>
lift2(A, B) => C(F<A>, F<B>) => F<C>
lift3(A, B, C) => D(F<A>, F<B>, F<C>) => F<D>

SemiCoproduct

SemiCoproduct is a universal semigroup which operates on kinds.

This type class is useful when its type parameter F<_> has a structure that can be combined for any particular type. Thus, SemiCoproduct is like a Semigroup for kinds (i.e. parametrized types).

A SemiCoproduct<F> can produce a Semigroup<F<A>> for any type A.

Here's how to distinguish Semigroup and SemiCoproduct:

  • Semigroup<A> allows two A values to be combined.

  • SemiCoproduct<F> allows two F<A> values to be combined, for any A. The combination operation just depends on the structure of F, but not the structure of A.

Extends:

  • Invariant
NameGivenTo
coproductF<A>, F<B>F<A | B>
coproductManyIterable<F<A>>F<A>
getSemigroupSemigroup<F<A>>
coproductEitherF<A>, F<B>F<Either<A, B>>

SemiProduct

Extends:

  • Invariant
NameGivenTo
productF<A>, F<B>F<[A, B]>
productManyF<A>, Iterable<F<A>>F<[A, ...ReadonlyArray<A>]>
productCompositionF<G<A>>, F<G<B>>F<G<[A, B]>>
productManyCompositionF<G<A>>, Iterable<F<G<A>>>F<G<[A, ...ReadonlyArray<A>]>>
nonEmptyTuple[F<A>, F<B>, ...]F<[A, B, ...]>
nonEmptyStruct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>
andThenBindF<A>, name: string, F<B>F<A & { [name]: B }>
productFlattenF<A>, F<B>F<[...A, B]>

Traversable

Traversal over a structure with an effect.

NameGivenTo
traverseApplicative<F>, T<A>, A => F<B>F<T<B>>
traverseCompositionApplicative<F>, T<G<A>>, A => F<B>F<T<G<B>>>
sequenceApplicative<F>, T<F<A>>F<T<A>>
traverseTapApplicative<F>, T<A>, A => F<B>F<T<A>>

TraversableFilterable

TraversableFilterable, also known as Witherable, represents list-like structures that can essentially have a traverse and a filter applied as a single combined operation (traverseFilter).

NameGivenTo
traversePartitionMapApplicative<F>, T<A>, A => F<Either<B, C>>F<[T<B>, T<C>]>
traverseFilterMapApplicative<F>, T<A>, A => F<Option<B>>F<T<B>>
traverseFilterApplicative<F>, T<A>, A => F<boolean>F<T<A>>
traversePartitionApplicative<F>, T<A>, A => F<boolean>F<[T<A>, T<A>]>

Adapted from:

版本与发布记录

@effect/typeclass 共发布 283 个版本,首次发布于 2023/07/09;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.41.0latest2026/07/134 个月前
0.40.02026/03/207 个月前
0.39.02026/03/177 个月前
0.38.02025/11/041 年前
0.37.02025/09/301.1 年前
0.36.02025/07/221.3 年前

其他发布通道:snapshot → 0.0.0-snapshot-6ebc752baf28354006ca2a0ae783a5bccf5de9ad。

关于 @effect/typeclass 的常见问题

@effect/typeclass 是什么?

A collection of reusable typeclasses for the Effect ecosystem

如何安装 @effect/typeclass?

在项目目录运行 npm install @effect/typeclass,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:effect(^3.22.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@effect/typeclass 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@effect/typeclass 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@effect/typeclass 可以商用吗?

@effect/typeclass 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@effect/typeclass 的下载量有多少?

根据 npm 官方下载统计,@effect/typeclass 在 2026/10/13 – 2026/11/11 这 30 天内被下载 1,018,887 次,日均约 33,963 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@effect/typeclass 还在维护吗?

最新版本 0.41.0 发布于 2026/07/13(4 个月前);至今共发布 283 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/07/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。