Skip to content

["Request"] Feedback to make Arrow more approachable #3303

Open
@schielek

Description

@schielek

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.

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.

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions