arrow-kt / arrow-kt/arrow

["Request"] Feedback to make Arrow more approachable

Open
#3,303 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
6.6k
Forks
472
Avg merge
3d 49m
Merged PRs (30d)
4

Description

# What version are you currently using?
`1.2.0`

# What would you like to see?
## What's great?
Arrow's raise DSL is a masterpiece of engineering. It has all the benefits of type-safe error handling without compromising green path programming and therefore fosters readability.

## Concrete vs. Abstract
I love that function names in the raise DSL are very concrete. `fun raise(r: Error): Nothing` clearly indicates that we deal with error handling here. A person not familiar with Arrow or even Kotlin can understand what the code does. `Either.Left` on the other hand is abstract. It takes time to get used to the convention that `Either.Left` models errors and `Either.Right` models the green path, but I feel like it is an unnecessary price to pay if I use `Either` only for error handling. (For other cases I have sealed data types and would never long for Either.)

## Suggestions for some Renaming/Aliases
### getOrRaise instead of/along with bind
I propose to introduce `getOrRaise` as an alias for `bind`. It goes along with other functions such as `getOrElse`, `getOrNull`, and `getOrNone`.
```kotlin
either {
// result is of type Either here
result.getOrElse { }
result.getOrNull()
result.getOrNone()
result.bind() // abstract and unreadable
result.getOrRaise() // does not exist :(
}
```

### get and error instead of/along with left and right
As mentioned before `left` and `right` are rather abstract.
```kotlin
// result is of type Either here
// Right cases have 'get' functions indicating success/green path
result.getOrElse { }
result.getOrNull()
result.getOrNone()

// Left cases only have 'left' functions. There isn't a readable alternative indicating errors
result.leftOrNull()
result.onLeft { }
result.mapLeft { }

// These would be better but do not exist
result.errorOrNull()
result.onError { }
result.mapError { }
```

### parMap and parZip
This is not part of the raise DSL but belongs into a similar category since it affects readability. Some function names such as `parMap` and `parZip` are directly taken from Haskell. While it is apparent to Haskell developers what these functions do, it might not be for the average Kotlin developer.
I suggest going with the Kotlin/Java philosophy of avoiding abbreviations where possible.
`parallelMap` and `parallelZip` have five more characters but can save a lot of headache when reading code.

## Note
This issue is rather meant as a feedback or an impulse for a discussion than a feature request. I would be happy if some people would join the conversation and leave their thoughts.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the raise DSL and Either entry points named in the issue, especially bind, left/right, and parMap/parZip, then read the existing discussion. This issue is feedback rather than a defined change; completion would require agreement on a specific naming direction before implementation can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.