scala-iso


License

License

MIT
Categories

Categories

Scala Languages
GroupId

GroupId

io.bartholomews
ArtifactId

ArtifactId

scala-iso_2.12
Last Version

Last Version

0.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

scala-iso
scala-iso
Project URL

Project URL

https://github.com/bartholomews/scala-iso
Project Organization

Project Organization

io.bartholomews
Source Code Management

Source Code Management

https://github.com/bartholomews/scala-iso

Download scala-iso_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.bartholomews/scala-iso_2.12/ -->
<dependency>
    <groupId>io.bartholomews</groupId>
    <artifactId>scala-iso_2.12</artifactId>
    <version>0.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.bartholomews/scala-iso_2.12/
implementation 'io.bartholomews:scala-iso_2.12:0.1.3'
// https://jarcasting.com/artifacts/io.bartholomews/scala-iso_2.12/
implementation ("io.bartholomews:scala-iso_2.12:0.1.3")
'io.bartholomews:scala-iso_2.12:jar:0.1.3'
<dependency org="io.bartholomews" name="scala-iso_2.12" rev="0.1.3">
  <artifact name="scala-iso_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.bartholomews', module='scala-iso_2.12', version='0.1.3')
)
libraryDependencies += "io.bartholomews" % "scala-iso_2.12" % "0.1.3"
[io.bartholomews/scala-iso_2.12 "0.1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.13
com.beachape : enumeratum_2.12 jar 1.6.1

test (1)

Group / Artifact Type Version
io.circe : circe-parser_2.12 jar 0.13.0

Project Modules

There are no modules declared in this project.

CircleCI License: MIT

scala-iso

Scala library for ISO enums

Maven Central

libraryDependencies += "io.bartholomews" %% "scala-iso" % "0.1.3"

ISO 3166-1 alpha-2

CountryCodeAlpha2 is a StringEnum (using enumeratum on the two-digits ISO string)

import io.bartholomews.iso.CountryCodeAlpha2
import io.circe._
import io.circe.syntax._

val italy: CountryCodeAlpha2 = CountryCodeAlpha2.ITALY

implicit val encoder: Encoder[CountryCodeAlpha2] = c => Json.fromString(c.value)
implicit val decoder: Decoder[CountryCodeAlpha2] = Decoder.decodeString.emap(
  str => CountryCodeAlpha2.values.find(_.value == str).toRight(s"Invalid ISO_3166-1 code: [$str]")
)

assert(italy.asJson == Json.fromString("IT"))
assert("IT".asJson.as[CountryCodeAlpha2].map(_.name) == Right("Italy"))

ISO 639-1

LanguageCode is a StringEnum (using enumeratum on the two-digits ISO string)

import io.bartholomews.iso.LanguageCode
import io.circe._
import io.circe.syntax._

val italy: LanguageCode = LanguageCode.ITALIAN

implicit val encoder: Encoder[LanguageCode] = c => Json.fromString(c.value)
implicit val decoder: Decoder[LanguageCode] = Decoder.decodeString.emap(
  str =>
    LanguageCode.values
      .find(_.value == str)
      .toRight(s"Invalid ISO_639 code: [$str]")
)

assert(italy.asJson == Json.fromString("it"))
assert("it".asJson.as[LanguageCode].map(_.name) == Right("Italian"))

Versions

Version
0.1.3
0.1.2
0.1.1
0.1.0