跳转到主要内容

让Python中的Monads变得简单和安全。

项目描述

dry-monads

wemake.services Build Status Coverage Status Documentation Status Python Version wemake-python-styleguide

python中的Monads变得简单和安全。

功能

  • 提供原语来编写声明式业务逻辑
  • 完全类型化,带有注释并通过mypy检查,允许您编写类型安全的代码
  • 没有操作符重载或其他令人眼花缭乱的未Python化内容

安装

pip install dry-monads

里面有什么?

我们有几个最标志性的Monads在里面

我们还关心代码可读性和开发者体验,因此我们包含了一些有用的功能,使您的生命更轻松

示例

from dry_monads.do_notation import do_notation
from dry_monads.either import Result, Success, Failure

class CreateAccountAndUser(object):
    """Creates new Account-User pair."""

    @do_notation
    def __call__(self, username: str, email: str) -> Result['User', str]:
        """Can return a Success(user) or Failure(str_reason)."""
        user_schema = self._validate_user(username, email).unwrap()
        account = self._create_account(user_schema).unwrap()
        return self._create_user(account)

    # Protected methods
    # ...

我们在文档中解释了这个示例中正在发生的事情

灵感

此模块主要基于

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

dry-monads-0.2.0.tar.gz (8.3 kB 查看哈希值)

上传时间 源代码

构建分布

dry_monads-0.2.0-py3-none-any.whl (22.9 kB 查看哈希值)

上传时间 Python 3