Skip to content

Defining schema for coordinates #14

Answered by SystemFw
marko-asplund asked this question in Q&A
Discussion options

You must be logged in to vote

The AttributeValue is slightly weird there, so I expect some friction. Couple of thoughts:

  • You can probably use Schema[List[Double]] as a starting point, which should save some code
  • You can use imapErrsince encoding doesn't fail.
  • If the list only has one value, how do you know (logically) whether x or y are missing?

I haven't tested it, but something like:

val coordSchema: Schema[Coordinate] =
  Schema[List[Double]].imapErr {
    case List(x, y) => Right(Coordinate(x, y))
    case _ => Left(ReadError("wrong coordinates")
  } { coord => List(coord.x, coord.y) }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@marko-asplund
Comment options

Answer selected by marko-asplund
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants