Nested functions in Java

Java 8 introduces lambdas. java.util.function.BiConsumer<Integer, Integer> times = (i, num) -> { i *= num; System.out.println(i); }; for (int i = 1; i < 100; i++) { times.accept(i, 2); //multiply i by 2 and print i times.accept(i, i); //square i and then print the result } The () -> syntax works on any interface that … Read more

Java pattern for nested callbacks?

Since the implementation (not only the interface) must not block, I like your list idea. Set up a list of “operations” (perhaps Futures?), for which the setup should be pretty clear and readable. Then upon receiving each response, the next operation should be invoked. With a little imagination, this sounds like the chain of responsibility. … Read more

Creating nested dataclass objects in Python

You can use post_init for this from dataclasses import dataclass @dataclass class One: f_one: int f_two: str @dataclass class Two: f_three: str f_four: One def __post_init__(self): self.f_four = One(**self.f_four) data = {‘f_three’: ‘three’, ‘f_four’: {‘f_one’: 1, ‘f_two’: ‘two’}} print(Two(**data)) # Two(f_three=”three”, f_four=One(f_one=1, f_two=’two’))

Nested Json to pandas DataFrame with specific format

If you load in the entire json as a dict (or list) e.g. using json.load, you can use json_normalize: In [11]: d = {“response”: {“body”: {“contact”: {“email”: “mr@abc.com”, “mobile_number”: “0123456789”}, “personal”: {“last_name”: “Muster”, “gender”: “m”, “first_name”: “Max”, “dob”: “1985-12-23”, “family_status”: “single”, “title”: “Dr.”}, “customer”: {“verified”: “true”, “customer_id”: “1234567”}}, “token”: “dsfgf”, “version”: “1.1”}} In [12]: df … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)