Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/earldouglas/linear-scala
Linear types in Scala
https://github.com/earldouglas/linear-scala
linear-types scala scalafix
Last synced: about 2 months ago
JSON representation
Linear types in Scala
- Host: GitHub
- URL: https://github.com/earldouglas/linear-scala
- Owner: earldouglas
- License: isc
- Created: 2021-05-16T15:29:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T16:20:48.000Z (2 months ago)
- Last Synced: 2024-10-31T17:12:49.147Z (2 months ago)
- Topics: linear-types, scala, scalafix
- Language: Scala
- Homepage:
- Size: 104 KB
- Stars: 39
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status][build-badge]][build-link]
[![Release Artifacts][release-badge]][release-link][build-badge]: https://github.com/earldouglas/linear-scala/workflows/build/badge.svg "Build Status"
[build-link]: https://github.com/earldouglas/linear-scala/actions "GitHub Actions"
[release-link]: https://oss.sonatype.org/content/repositories/releases/com/earldouglas/linear-scala/ "Sonatype Releases"
[release-badge]: https://img.shields.io/nexus/r/https/oss.sonatype.org/com.earldouglas/linear-scala "Sonatype Releases"# linear-scala
linear-scala adds support for linear types in Scala via a custom
Scalafix linter.## Setup
*project/plugins.sbt:*
```scala
addSbtPlugin("com.earldouglas" % "sbt-linear-scala" % "0.0.3")
```## Usage
Mix in the `Linear` interface to prevent values from being
under/over-used.
```scala
import com.earldouglas.linearscala.Linearcase class Box(value: Int) extends Linear
```Scalafix finds values that are never used:
```scala
trait UnusedField {
val box: Box = Box(42) // error: box is never used
}trait UnusedParameter {
def foo(x: Box, y: Box): Int = // error: y is never used
x.value
}
```Scalafix also finds values that are used multiple times:
```scala
trait FieldUsedTwice {
val box: Box = Box(42)
println(box) // error: box is used twice
println(box) // error: box is used twice
}
```See the tests in [input/src/main/scala/fix/](input/src/main/scala/fix/)
for more examples.## References
### Linear Types
*
*
*
*