Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sealerate

Build Status Current Version Apache 2.0 License

Sealerate is a small (3rd-party-dependency-free) library that provides convenience functions values[T] and collect[T] that dynamically create a set of all instances of a sealed class.

Set Up

Sealerate is available for Scala 2.10, 2.11, 2.12, and 2.13. If you are using sbt, add the following to your build.sbt:

libraryDependencies += "ca.mrvisser" %% "sealerate" % "0.0.6"

Example Usage

package example

import ca.mrvisser.sealerate

sealed trait Switch
object Switch {
    case object On extends Switch
    case object Off extends Switch

    /**
     * Enumerate all instances of of the [[Switch]] trait
     */
    def values: Set[Switch] = sealerate.values[Switch]
}

Now Switch.values will provide Set(On, Off), and will update automatically when new objects are added.

Note that a compilation error is thrown if the following conditions aren't met:

  • The given type T is not a sealed trait, sealed abstract class or sealed class
  • The case instances of type T are not all case objects. (As an alternative the collect[T] function will simply filter out case classs instead of throw an error)

Contributors

About

A scala convenience library to get Java enum functionality out of sealed classes.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages