Defining schema for coordinates #14
Answered
by
SystemFw
marko-asplund
asked this question in
Q&A
-
I'm trying to define schema for representing coordinates. It's an existing data model that looks like this:
The following declaration seems to be working, but is a bit verbose.
|
Beta Was this translation helpful? Give feedback.
Answered by
SystemFw
Dec 29, 2021
Replies: 1 comment 1 reply
-
The AttributeValue is slightly weird there, so I expect some friction. Couple of thoughts:
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) } |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
marko-asplund
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The AttributeValue is slightly weird there, so I expect some friction. Couple of thoughts:
Schema[List[Double]]
as a starting point, which should save some codeimapErr
since encoding doesn't fail.x
ory
are missing?I haven't tested it, but something like: