arrow-kt / arrow-kt/arrow-analysis

Conversion from base types

Open
#37 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
30
Forks
3
PR merge metrics
No merged PRs in 30d

Description

(From a conversation on Slack)

The idea is to automatically provide conversions or constructors from basic types to classes with invariants.Some ideas:

- For `value class` we create from the base type to the type with invariants, as in the case above. Maybe we should return `String?` instead.

```kotlin
@JvmInline
value class String5(val value: String) {
init {
require(value.length < 5)
}
}

fun String.asString5() = if (this.length < 5) {
String5(this).right()
} else {
"String '$this' should be smaller than 5".left()
}
```

- Conversely, we could add pseudo-constructors in the companion object which return the type but nullable.

```kotlin
@JvmInline
value class String5(val value: String) {
init {
require(value.length < 5)
}

companion object {
fun attempt(value: String): String5? = ...
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The proposal comes from a Slack conversation and names no files, tests, or entry points. Start by reviewing the Arrow Analysis Plugin's existing support for value classes and invariants, then clarify which conversion or constructor API is intended. Done requires an agreed design and documented behavior for the proposed conversions.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
compilers, tooling
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.