https://github.com/vic/typeset
An Scala type-indexed set, checked at compile time.
https://github.com/vic/typeset
scala type-indexed-set type-level-programming
Last synced: 3 months ago
JSON representation
An Scala type-indexed set, checked at compile time.
- Host: GitHub
- URL: https://github.com/vic/typeset
- Owner: vic
- License: apache-2.0
- Created: 2021-12-23T00:21:00.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-07-15T04:35:58.000Z (5 months ago)
- Last Synced: 2025-07-15T10:24:48.480Z (5 months ago)
- Topics: scala, type-indexed-set, type-level-programming
- Language: Scala
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# typeset [](https://github.com/vic/typeset/actions)
An Scala Type indexed set checked at compile time.
a TypeSet is similar to ZIO's `Has[_]` type but without any reflection need.
### Adding to your project.
Jars are available for all versions and commits at Jitpack.io.
[](https://jitpack.io/#vic/typeset)
### Usage
Creating a TypeSet is always done by prepending something to `TNil`, which
represent the empty `TypeSet`.
```scala
import typeset.*
val x = "Hello" :+: TNil
```
Of course, being a Set, you can't duplicate types of values on it.
```scala
// val bad = "Hello" :+: "World" :+: TNil // This wont compile!!
```
The type of the set can be re-arrenged on the left side and any combination
containing the same types should be valid.
```scala
val a: String :+: Boolean :+: Int :+: TNil = "Hello" :+: true :+: 42 :+: TNil
val b: Int :+: String :+: Boolean :+: TNil = a // types are the same.
```
TypeSets can be joined together if they contained types do not cause duplicates.
```scala
val a = 1 :+: TNil
val b = true :+: TNil
val c = a :+: b // Has type Int :+: Boolean :+: TNil
```
Once created, you can obtain the value of a type from a Set.
```scala
val a = true :+: "Hello" :+: TNil
val x: String = a.get[String] // Returns "Hello"
```
Removing a type returns it's current value and another collapsed set without the
type present.
```scala
val a = true :+: "Hello" :+: TNil
val (x: String, b) = a.drop[String]() // type of b is Boolean :+: TNil
```
That's pretty much it. For more examples you can see the [test code](typeset/test/src).
### Contributing
All contributions are welcome, just please be kind and repectful of other
people's time.
For Building, you will need [mill](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html) installed.
```sh
mill __.test # This will run all tests
```