{"id":19422525,"url":"https://github.com/scalalandio/enumz","last_synced_at":"2025-04-24T15:32:22.385Z","repository":{"id":57736151,"uuid":"147009068","full_name":"scalalandio/enumz","owner":"scalalandio","description":"One enum type class to rule them all","archived":false,"fork":false,"pushed_at":"2025-04-20T19:50:38.000Z","size":302,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T20:33:18.052Z","etag":null,"topics":["enum","enumeration","enumerator","java-enums","scala","type-class"],"latest_commit_sha":null,"homepage":"https://enumz.readthedocs.io/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scalalandio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-09-01T15:15:24.000Z","updated_at":"2025-04-20T19:50:41.000Z","dependencies_parsed_at":"2024-11-10T13:35:40.509Z","dependency_job_id":"99479cc2-fe9c-4002-8a20-aa607265a757","html_url":"https://github.com/scalalandio/enumz","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalalandio%2Fenumz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalalandio%2Fenumz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalalandio%2Fenumz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalalandio%2Fenumz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scalalandio","download_url":"https://codeload.github.com/scalalandio/enumz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250654480,"owners_count":21465890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["enum","enumeration","enumerator","java-enums","scala","type-class"],"created_at":"2024-11-10T13:34:04.878Z","updated_at":"2025-04-24T15:32:22.094Z","avatar_url":"https://github.com/scalalandio.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enumz\n\n[![Chimney Scala version support](https://index.scala-lang.org/scalalandio/enumz/enumz/latest.svg)](https://index.scala-lang.org/scalalandio/enumz/enumz)\n\n[![CI build](https://github.com/scalalandio/enumz/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/scalalandio/enumz/actions)\n[![License](http://img.shields.io/:license-Apache%202-green.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)\n\n[![Documentation Status](https://readthedocs.org/projects/enumz/badge/?version=latest)](https://readthedocs.org/projects/enumz/builds/)\n[![Scaladoc 2.11](https://javadoc.io/badge2/io.scalaland/enumz_2.11/scaladoc%202.11.svg)](https://javadoc.io/doc/io.scalaland/enumz_2.11)\n[![Scaladoc 2.12](https://javadoc.io/badge2/io.scalaland/enumz_2.12/scaladoc%202.12.svg)](https://javadoc.io/doc/io.scalaland/enumz_2.12)\n[![Scaladoc 2.13](https://javadoc.io/badge2/io.scalaland/enumz_2.13/scaladoc%202.13.svg)](https://javadoc.io/doc/io.scalaland/enumz_2.13)\n[![Scaladoc 3](https://javadoc.io/badge2/io.scalaland/enumz_3/scaladoc%203.svg)](https://javadoc.io/doc/io.scalaland/enumz_3)\n\nOne enum type class to rule them all.\n\nIn Scala, you might meet many different implementations of enums:\n\n * build-in `scala.Enumeration`,\n * sum-type based sealed hierarchies,\n * `enumeratum` as the previous one on steroids,\n * Java's `enum` type which use static methods and has no companion object.\n\nYou are in control of what implementation *you* pick, but you have no control over\nwhat *other people* use. So if you had to use APIs using many different\nimplementations how would you handle common code?\n\nWith a type class.\n\n## Usage\n\nAdd to your sbt (2.12, 2.13 and 3.3+ supported)\n\n```scala\nlibraryDependencies += \"io.scalaland\" %% \"enumz\" % enumzVersion // see Maven badge\n```\n\nor, if you use Scala.js\n\n```scala\nlibraryDependencies += \"io.scalaland\" %%% \"enumz\" % enumzVersion // see Maven badge\n```\n\nFrom now on you can define enums whatever you want and use one common interface\nfor all of them.\n\n```java\npublic enum TestJavaEnum {\n    A, B, C\n}\n```\n\n```scala\nobject TestEnumeration extends Enumeration {\n  type TestEnumeration = Value\n  val A, B, C = Value\n}\n```\n\n```scala\nsealed trait TestSumType extends Product with Serializable\nobject TestSumType {\n  case object A extends TestSumType\n  case object B extends TestSumType\n  case object C extends TestSumType\n}\n```\n\n```scala\nimport enumeratum.{Enum =\u003e EnumeratumEnum, _}\n\nsealed trait TestEnumeratum extends EnumEntry\nobject TestEnumeratum extends EnumeratumEnum[TestEnumeratum] {\n  val values = findValues\n  case object A extends TestEnumeratum\n  case object B extends TestEnumeratum\n  case object C extends TestEnumeratum\n}\n```\n\n```scala\nimport io.scalaland.enumz.Enum\n\nEnum[TestJavaEnum].values\nEnum[TestEnumeration.TestEnumeration].values\nEnum[TestSumType].values\nEnum[TestEnumeratum].values\n```\n\nYou can also test it with ammonite like:\n\n```scala\nimport $ivy.`io.scalaland::enumz:1.0.0`, io.scalaland.enumz.Enum\n\n{\nsealed trait TestSumType extends Product with Serializable\nobject TestSumType {\n  case object A extends TestSumType\n  case object B extends TestSumType\n  case object C extends TestSumType\n}\n}\n\nEnum[TestSumType].values\n```\n\n## Methods\n\n```scala\nEnum[TestSumType].values // Vector(TestSumType.A, TestSumType.B, TestSumType.C)\nEnum[TestSumType].indices // Map(TestSumType.A -\u003e 0, TestSumType.B -\u003e 1, TestSumType.C -\u003e 2)\n\nEnum[TestSumType].getName(TestSumType.A) // \"A\"\nEnum[TestSumType].getIndex(TestSumType.A) // 0\n\nEnum[TestSumType].withIndexOption(0) // Some(TestSumType.A)\nEnum[TestSumType].withIndexOption(-1) // None\n\nEnum[TestSumType].withIndex(0) // TestSumType.A\nEnum[TestSumType].withIndex(-1) // throws!\n\nEnum[TestSumType].withNameOption(\"A\") // Some(TestSumType.A)\nEnum[TestSumType].withNameOption(\"\") // None\n\nEnum[TestSumType].withName(\"A\") // TestSumType.A\nEnum[TestSumType].withName(\"\") // throws!\n\nEnum[TestSumType].withNameInsensitiveOption(\"a\") // Some(TestSumType.A)\nEnum[TestSumType].withNameInsensitiveOption(\"\") // None\n\nEnum[TestSumType].withNameInsensitive(\"a\") // TestSumType.A\nEnum[TestSumType].withNameInsensitive(\"\") // throws!\n\nEnum[TestSumType].`A` // TestSumType.A\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalalandio%2Fenumz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscalalandio%2Fenumz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalalandio%2Fenumz/lists"}