Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonDecoder.{zip, zipRight, ...} don't preserve their laziness #587

Open
felher opened this issue Mar 9, 2022 · 0 comments
Open

JsonDecoder.{zip, zipRight, ...} don't preserve their laziness #587

felher opened this issue Mar 9, 2022 · 0 comments

Comments

@felher
Copy link

felher commented Mar 9, 2022

As discussed on discord:

Even though zip, zipLeft, zipRight and zipWith on JsonDecoder all take their second decoder by name, they internally delegate to JsonDecoder.tuple2. This renders them effectively non-lazy.

Here is an example of code which one might expect to work but which throws a stack overflow error:

import zio.json.*

final case class Tree(value: Int, children: List[Tree])
object Tree:
  implicit def decoder: JsonDecoder[Tree] =
    JsonDecoder[Int].zipWith(JsonDecoder.list(decoder))(Tree.apply)

@main()
def run = 
  println("[1, [[2, []]]]".fromJson[Tree])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant