Add function on EitherAssert for chaining Left and Right into Non Empty Lists
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
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc các API assertion hiện có của EitherAssert và NonEmptyList, sau đó so sánh các shortcut asLeftNel()/asRightNel() được đề xuất với cách tiếp cận trích xuất giá trị thay thế. Kiểm tra xem có cần một giải pháp tương tự cho Raise hay không và định nghĩa các assertion tập trung bao quát các trường hợp sử dụng Either và NonEmptyList được yêu cầu; issue cần có quyết định về thiết kế trước khi triển khai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
While converting some more tests, I encountered another use case that feels like it could be a bit more accessible.
When you have code that uses NonEmptyLists inside Eithers, it's not terribly idiomatic to get them out in order to assert on them. For example
fun returnsNel(): Either<NonEmptyList<String>, Int> {
return nonEmptyListOf("error", "other error")
}
@Test
fun assertOverLeftNel() {
val result = returnsNel()
// either assert
assertThat(result).isLeft()
val unwrappedResult = result.leftOrNull()!!
// non empty list assert
assertThat(unwrappedResult).contains("error", "other error")
}
either assert asLeft / containsLeftInstanceOf will give you an object assertion for the NonEmptyList, but there's no easy way to get to the underlying object in order to begin a NonEmptyList assertion. If you just want to do an assertion on the full list using equality you can do a assertThat(result).containsOnLeft(nonEmptyListOf("error", "other error") - but that's it, we're missing many of the other tools for NonEmptyList asserts such as just matching one element, matching on some elements, checking for sorting. I think combining Eithers/raises that then contain NonEmptyLists on the left side is a particularly common usecase in Arrow, see aliases such as EitherNel, and functions like bindNel
This is sort of also a limitation on the base library, as there's not really a super easy way to extract out a property of a complex object and get to its relevant special case assertions, however in practice I think this is particularly a bit more of pain here due to the ubiquitously wrapped nature of Eithers, that try to enforce safety.
I can think of two possible solutions for this, one would be to offer some shortcuts into the special case assertions, something like a asLeftNel() and asRightNel() option that would verify the Either had the appropriate side, was of type NonEmptyList, and launch right into the NonEmptyList assertions. So that would be used something like assertThat(result).asLeftNel().isSorted()
The other option would be a value that allows for assigning from an asLeft or asRight call. This could be a new method, like asLeftValue(), or an extension property on AbstractObjectAssertion like .value
I haven't directly encountered this for Raise, but given the Raise works with all the same orAccumulate patterns, I think it likely makes sense to complete a similar solution there.
At first blush I think I might lean towards the special case for NonEmptyLists of asLeftNel() - but would be open to input on what you think might make the most sense. I'm happy to work towards an implementation if this makes sense to you. Thanks!
- Ngôn ngữ chính
- Kotlin
- Star
- 13
- Fork
- 6
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của assertj/assertj-arrow-core
-
Dependency Dashboard Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 10/100
Tất cả issue của assertj/assertj-arrow-core
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Richie97/track-history#325 ·
-
bug CLI documentation reliability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
KW-related Type:bug UI / UX
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
RevenueCat/purchases-android#4299 · 1 bình luận ·
-
[Bug] 统计页面无法重置token和汇率 Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
AAswordman/Operit#1265 · 3 bình luận ·