Last active
August 29, 2015 14:01
-
-
Save matthughes/c905557fbd85f4e91709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def AgentCodecJson: CodecJson[Agent] = | |
CodecJson( | |
(agent: Agent) => jString(agent match { | |
case Agent.System => "System" | |
case Agent.User(name) => name | |
}), | |
c => c.focus.string.map { | |
_ match { | |
case "System" => Agent.System | |
case username => Agent.User(username) | |
} | |
} | |
) | |
// Becomes | |
implicit def AgentCodecJson: CodecJson[Agent] = { | |
CodecJson( | |
implicitly[EncodeJson[String]].contramap { | |
_ match { | |
case Agent.System => "System" | |
case Agent.User(name) => name | |
} | |
}, | |
implicitly[DecodeJson[String]].map { | |
_ match { | |
case "System" => Agent.System | |
case username => Agent.User(username) | |
} | |
} | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment