Add function on EitherAssert for chaining Left and Right into Non Empty Lists
まだ誰も着手していません。
評価
調査の方向性
まず既存のEitherAssertおよびNonEmptyListのアサーションAPIを読み、提案されているasLeftNel()/asRightNel()ショートカットを、値を抽出する別のアプローチと比較します。Raiseにも同様の解決策が必要かを確認し、要求されているEitherおよびNonEmptyListのユースケースをカバーする、対象を絞ったアサーションを定義します。このissueでは、実装前に設計上の判断が必要です。
索引モデルが issue の本文から書いたものです。
説明
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!
- 主要言語
- Kotlin
- スター
- 13
- フォーク
- 6
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
assertj/assertj-arrow-core のほかの issue
-
Dependency Dashboardオープン
難易度 4/5 3〜5日 初心者へのやさしさ 10/100
assertj/assertj-arrow-core の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 73/100
tortuvshin/open-apps#377 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
supabase-community/supabase-kt#1413 ·
メンテナーはふだん 5 日以内に返信
-
Type: Possible bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
spacecowboy/Feeder#1258 ·
メンテナーはふだん 1 日以内に返信
-
[Submission] 抖音火山版オープンsubmit-adaption submit-adaption-pre
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
BetterAndroid/android-notification-icon-project#744 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
utopia-rise/godot-jvm#1004 ·
メンテナーはふだん 1 日以内に返信