Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created February 28, 2013 10:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandubian/5055738 to your computer and use it in GitHub Desktop.
Save mandubian/5055738 to your computer and use it in GitHub Desktop.
Class Rectangle
val rectWrites = (
(__ \ 'width).write[Long] and
(__ \ 'height).write[Long] and
(__ \ 'x).write[Long] and
(__ \ 'y).write[Long]
)( (r: Rectangle) => (r.width, r.height, r.x, r.y) )
@gre
Copy link

gre commented Feb 28, 2013

aha we can rewrite all awt* writers!

  implicit object ColorWrites extends Writes[Color] {
    def writes(c: Color) = JsString(
      "#"+
      Integer.toHexString(c.getRed())+
      Integer.toHexString(c.getGreen())+
      Integer.toHexString(c.getBlue())
    )
  }

@mandubian
Copy link
Author

aha we can rewrite all awt* writers!

  implicit val ColorWrites = Writes[Color] { c => 
    JsString(
      "#"+
      Integer.toHexString(c.getRed())+
      Integer.toHexString(c.getGreen())+
      Integer.toHexString(c.getBlue())
    )
  }

@gre
Copy link

gre commented Feb 28, 2013

  implicit val ColorWrites = Writes[Color] { c =>
    JsString("#%02x%02x%02x" format (c.getRed, c.getGreen, c.getBlue))
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment