Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 2 days 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 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-26T02:16:17.000Z (about 2 years ago)
- Last Synced: 2024-10-11T22:24:10.022Z (28 days ago)
- Topics: scala, type-indexed-set, type-level-programming
- Language: Scala
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# typeset [![Main workflow](https://github.com/vic/typeset/actions/workflows/workflow.yml/badge.svg)](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/v/vic/typeset.svg)](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
```