SM

samber/mo

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

3431 stars 质量 72 趋势 41MIT

🦄 Monad 和流行的 FP 抽象,由 Go 1.18+ Generics(Option、Result、Ot...)驱动

概览

- samber/ro:反应式编程 for Go:声明式且可组合的事件驱动应用 - samber/lo:基于 Go 1.18+ 通用代码的 Lodash 风格 Go 库 - samber/do:基于 Go 1.18+ 的依赖注入工具包 通用代码 - samber/cc-skills-golang:Golang 的 AI 代理技能 💖 赞助商:DBOS - Go 的持久工作流程编排库 我很喜欢这种实用库。这个名字和“Monad Go”很像,没有哪个 Go 包用这个名字。 我们目前支持以下数据类型: - 选项[T](可能)- 结果[T] - 任一[A, B] - 任一X[T1, ..., TX](X在3和5之间)- 未来[T] - IO[T] - IOEither[T] - 任务[T] - TaskEither[T] - 状态[S, A] 这个库是v1,严格遵循SemVer。 在 v2.0.0 之前,导出的 API 不会做任何破坏性更改。 这个库除了 Go 标准库外没有其他依赖。

概述(AI 翻译)

🦄 samber/mo 将单子和流行的 FP 抽象带入 Go 项目。[samber/mo 使用了最近的 Go 1.18+ Generics。

灵感来源:

  • 斯卡拉
  • 锈蚀
  • FP-TS

参见:

  • samber/ro:Go 反应式编程:用于事件驱动应用的声明式和可组合 API
  • samber/lo:基于 Go 1.18+ 通用代码的 Lodash 风格 Go 库
  • samber/do:基于 Go 1.18+ 通用代码的依赖注入工具包
  • samber/cc-skills-golang:Golang 的 AI 代理技能

💖 赞助商:

DBOS - Go 的持久工作流程编排库


为什么叫这个名字?

我喜欢用简短名称来形容这种实用库。这个名字和“Monad Go”很像,没有哪个Go包用这个名字。

💡 特色

我们目前支持以下数据类型:

  • Option[T](也许)
  • Result[T]
  • Either[A, B]
  • EitherX[T1, ..., TX](X介于3和5之间)
  • Future[T]
  • IO[T]
  • IOEither[T]
  • Task[T]
  • TaskEither[T]
  • State[S, A]

🚀 安装

这个库是v1,严格遵循SemVer。

在 v2.0.0 之前,导出的 API 不会做任何破坏性更改。

这个库除了 Go 标准库外没有其他依赖。

💡 快速开始

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mo - Monads

🦄 samber/mo brings monads and popular FP abstractions to Go projects. samber/mo uses the recent Go 1.18+ Generics.

Inspired by:

  • Scala
  • Rust
  • FP-TS

See also:

  • samber/ro: Reactive Programming for Go: declarative and composable API for event-driven applications
  • samber/lo: A Lodash-style Go library based on Go 1.18+ Generics
  • samber/do: A dependency injection toolkit based on Go 1.18+ Generics
  • samber/cc-skills-golang: AI Agent Skills for Golang


Why this name?

I love short name for such utility library. This name is similar to “Monad Go” and no Go package uses this name.

💡 Features

We currently support the following data types:

  • Option[T] (Maybe)
  • Result[T]
  • Either[A, B]
  • EitherX[T1, ..., TX] (With X between 3 and 5)
  • Future[T]
  • IO[T]
  • IOEither[T]
  • Task[T]
  • TaskEither[T]
  • State[S, A]

🚀 Install

go get github.com/samber/mo@v1

# AI Agent Skill
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-mo

This library is v1 and follows SemVer strictly.

No breaking changes will be made to exported APIs before v2.0.0.

This library has no dependencies except the Go std lib.

💡 Quick start

You can import mo using:

import (
    "github.com/samber/mo"
)

Quick example using the option sub-package Pipe3 to compose transformations:

import (
    "github.com/samber/mo"
    "github.com/samber/mo/option"
)

out := option.Pipe3(
    mo.Some(21),
    option.Map(func(v int) int { return v * 2 }),
    option.FlatMap(func(v int) mo.Option[int] { return mo.None[int]() }),
    option.Map(func(v int) int { return v + 21 }),
)
// out == None[int]

Then use one of the helpers below:

在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add samber/mo
新手?先看 mcpskill.org 教程 →