搜索插件、代码仓与 APP 分类

插件详情v0.10.1

dartz

Dart 中的函数式编程。使用高效的不可变数据结构、单子、透镜和其他 FP 工具来净化您的 Dart 代码。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
58.3万
喜欢数
1560
Pub 分数
130

安装插件

flutter pub add dartz

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Dartz 是一个 Dart 库,将函数式编程概念引入 Dart,使开发者能够编写更清晰、更可预测的代码。它提供了不可变数据结构、Either 和 Option 等单子,以及用于安全数据操作的工具(如透镜)。通过倡导纯粹性并避免副作用,Dartz 以类型安全的方式管理错误和可选值。非常适合构建具有清晰错误处理和状态管理的健壮、可维护的应用程序。

适合场景

  • 错误处理与 Either
  • 使用 Option 管理可选值
  • 构建纯函数
  • 创建可组合的业务逻辑
  • 实现功能状态管理
  • 编写可测试且可维护的代码

主要特点

  • 不可变数据结构
  • 用于错误处理的 Either monad
  • 可空值的选项类型
  • 用于函数式更新的镜头
  • 类型安全的组合
  • 轻量且高效

适合对象

  • 寻求在 Dart 中进行函数式编程的开发者
  • 致力于纯粹且可测试代码的团队
  • 需要强大错误处理的应用程序
  • 专注于清洁架构的项目
  • 前端和后端 Dart 应用程序

使用建议

  • 需要理解函数式编程概念
  • 可能增加初学者的学习曲线
  • 不适合简单的脚本或快速原型
  • 最好用于较大且结构化的应用程序
  • 与非功能性代码的集成可能需要进行适配

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

dartz

License Pub.dev Github Stars

Functional programming in Dart

  • Type class hierarchy in the spirit of cats, scalaz and the standard Haskell libraries
  • Immutable, persistent collections, including IVector, IList, IMap, IHashMap, ISet and AVLTree
  • Option, Either, State, Tuple, Free, Lens and other tools for programming in a functional style
  • Evaluation, a Reader+Writer+State+Either+Future swiss army knife monad
  • Type class instances (Monoids, Traversable Functors, Monads and so on) for included types, as well as for several standard Dart types
  • Conveyor, an implementation of pure functional streaming
  • Examples, showcasing core concepts
New to functional programming?

A good place to start learning is the excellent Functional Programming in Scala by Paul Chiusano and Rúnar Bjarnason. I can not recommend this book highly enough.
You can also take a look at Category Theory for Programmers by Bartosz Milewski.

Status
  • Starting with version 0.10.0, Dart 2.12+ is required
  • 0.9.x supports Dart 1 and older Dart 2 versions
  • Basic type class structure and collection classes are relatively stable, but might see restructuring in future releases
  • Optimized for dart2js/node/v8, with performance on the dart vm being of distant secondary concern
  • Most things are stack safe and reasonably efficient, but there are a couple of exceptions and plenty of room for further optimizations
  • The streaming/conveyor stuff is highly experimental
  • The lens implementation is experimental and very bare bones
License/Disclaimer

See LICENSE

所属分类

源码仓库

使用此插件的项目