Skip to content

Instantly share code, notes, and snippets.

@phdoerfler
Created April 13, 2021 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phdoerfler/74a25b79ceeda9408ddd015d486cda12 to your computer and use it in GitHub Desktop.
Save phdoerfler/74a25b79ceeda9408ddd015d486cda12 to your computer and use it in GitHub Desktop.
{
"Case class tuple codec": {
"prefix": "scircetuple",
"body": [
"import io.circe._",
"case class ${1:MyCaseClass}(${2:_1}: ${3:Double}, ${4:_2}: ${5:String})",
"object ${1} {",
" implicit val codec: Codec[${1}] = Codec.from(",
" implicitly[Decoder[(${3}, ${5})]].map((${1}.apply _).tupled),",
" implicitly[Encoder[(${3}, ${5})]].contramap(r => (r.${2}, r.${4}))",
" )",
"}"
],
"description": "Creates a case class and codec for dealing with tuples in circe, AKA arrays with mixed types"
},
"Case class tuple codec 2": {
"prefix": "scircetuple",
"body": [
"import io.circe._",
"case class ${1:MyCaseClass}(${2:_1}: ${3:Double}, ${4:_2}: ${5:String})",
"object ${1} {",
" implicit val codec: Codec[${1}] = Codec.from(",
" implicitly[Decoder[(${3}, ${5})]].map((${1}.apply _).tupled),",
" implicitly[Encoder[(${3}, ${5})]].contramap(r => ${1}.unapply(r).get)",
" )",
"}"
],
"description": "Creates a case class and codec for dealing with tuples in circe, AKA arrays with mixed types"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment