Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2024 12 create codec #349

Merged
merged 12 commits into from
Dec 31, 2024
Merged

Feature/2024 12 create codec #349

merged 12 commits into from
Dec 31, 2024

Conversation

takapi327
Copy link
Owner

@takapi327 takapi327 commented Dec 31, 2024

Implementation Details

If both Encoder and Decoder were needed, each had to be defined. With this modification, a new Codec has been added, allowing Encoder and Decoder to be defined together.

enum Status:
  case Active, InActive

-given Encoder[Status] = Encoder[Boolean].contramap {
-  case Status.Active   => true
-  case Status.InActive => false
-}

-given Decoder[Status] = Decoder[Boolean].map {
-  case true  => Status.Active
-  case false => Status.InActive
-}

+given Codec[Status] = Codec[Boolean].imap {
+  case true => Status.Active
+  case false => Status.InActive
+} {
+  case Status.Active   => true
+  case Status.InActive => false
+}

It can also be used in place of a Decoder or Encoder by building a Codec.

-given Decoder[City] = (Decoder[Int] *: Decoder[String] *: Decoder[Int]).to[City]
+given Codec[City] = (Codec[Int] *: Codec[String] *: Codec[Int]).to[City]

Pull Request Checklist

  • Wrote unit and integration tests
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code formatting by scalafmt (sbt scalafmtAll command execution)
  • Add copyright headers to new files

References

@takapi327 takapi327 added 🚀 feature New feature project:dsl Addition and modification of functionality to DSL projects labels Dec 31, 2024
@takapi327 takapi327 added this to the 0.3.0 milestone Dec 31, 2024
@takapi327 takapi327 self-assigned this Dec 31, 2024
@takapi327 takapi327 merged commit 96d79ef into master Dec 31, 2024
27 checks passed
@takapi327 takapi327 deleted the feature/2024-12-Create-Codec branch December 31, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 feature New feature project:dsl Addition and modification of functionality to DSL projects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant