Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Adding some utility methods to Maybe/Result

Đang mở
#1,114 20 bình luận 7 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu bằng việc xem xét các triển khai container Maybe và Result cũng như phần thảo luận trong issue liên quan #1091. Xác định những phương thức được đề xuất nào trong số setdefault, zip, filter, and_ và or_ nằm trong phạm vi, sau đó xác nhận hành vi của chúng đối với các container thành công và rỗng bằng các bài kiểm thử; hoàn thành có nghĩa là các tiện ích và ví dụ đã thống nhất được triển khai nhất quán.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

Have you considered adding some handy utility functions to Maybe and Result?
In using returns I'm missing many helpful methods you can find in Rust, for example.
Adding a few of these could increase the usability of the containers of returns.

Related: #1091

Here they are, in my subjective order of usefulness:

Setdefault

Set a value if one is not yet present.
The name setdefault would be consistent with the python dict method.
(Although it might be good to choose another name to make clear that
the method doesn't mutate.)

>>> Some(6).setdefault(7)
Some(6)
>>> Nothing.setdefault(3)
Some(3)

Zip

Combine the values from two containers into a tuple, if both are successful.

>>> Some(8).zip(Some(2))
Some((8, 2))
>>> Some(7).zip(Nothing)
Nothing
>>> Nothing.zip(Some(3))
Nothing
>>> Nothing.zip(Nothing)
Nothing

Filter

Keep a value based on a predicate

>>> Some("9").filter(str.isdigit)
Some("9")
>>> Some("foo3").filter(str.isdigit)
Nothing
>>> Nothing.filter(str.isdigit)
Nothing

And

AND logic operation

>>> Some(5).and_(Some(9))
Some(9)
>>> Some(9).and_(Nothing)
Nothing
>>> Nothing.and_(Some(8))
Nothing

Or

OR logic operation

>>> Some(5).or_(Some(9))
Some(5)
>>> Some(9).or_(Nothing)
Some(9)
>>> Nothing.or_(Some(8))
Some(8)
>>> Nothing.or_(Nothing)
Nothing
Ngôn ngữ chính
Python
Star
4.4k
Fork
154
Merge trung bình
3 giờ 5 phút
Pull request đã merge (30 ngày)
22

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dry-python/returns

Tất cả issue của dry-python/returns

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.