Another thing with this library, is there a way to...
# arrow
d
Another thing with this library, is there a way to get an
Every<JsonElement, Foo>
?
s
I think you should write a
Prism
for this. cc\ @Alejandro Serrano Mena
d
string
seems to be implemented like this:
Copy code
private object JsonElementToString : Optional<JsonElement, String> {
  override fun getOrModify(source: JsonElement): Either<JsonElement, String> =
    source.jsonPrimitiveOrNull?.let { json ->
      if (json.isString) json.content.right() else json.left()
    }
      ?: source.left()

  override fun set(source: JsonElement, focus: String): JsonElement =
    if (source is JsonPrimitive && source.isString) JsonPrimitive(focus) else source
}
But when I try using
Copy code
Optional<JsonElement, Foo>(
    getOrModify = *{*

    *}*, set = *{}*
)
intellij doesn't know what to import...
a
what are you trying to do exactly?
d
Given:
[{ "id":1, "name": "this"}, {"id":2, "name": "that"}]
Getting each element in:
data class Foo(id: Int, name: String)
(the actual json could be more complex...)
w/o having to make a complex implementation for making a lens on each such mapping...
If the fields are there the optional returns something, if not than just
none
... I think that's how
string
works too, no?
A big plus would be to use the JsonPath DSL to reach those fields in such a mapper...
Ooooh, that's GREAT! I just found
_extract_()
... ­čĹŹ­čĆ╝