Skip to content
Discussion options

You must be logged in to vote

I believe what you were missing in the original example is bindNelOrAccumulate, which exists in current Arrow. Using a combine function worked because then you replaced bindAll with bind, which then resolved to the inner RaiseAccumulate.
I would rewrite your code like this in modern Arrow:

data class Author private constructor(val name: String) {
  companion object {
    context(_: RaiseAccumulate<BookValidationError>)
    operator fun invoke(name: String): Author {
      ensureOrAccumulate(name.isNotEmpty()) { EmptyAuthorName }
      ensureOrAccumulate(name.length > 3) { InvalidAuthorName(name) }
      return Author(name)
    }
  }
}

data class Book private constructor(
  val title: String

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kyay10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants