How to call a named constructor from a generic function in Dart/Flutter

Dart does not support instantiating from a generic type parameter. It doesn’t matter if you want to use a named or default constructor (T() also does not work). There is probably a way to do that on the server, where dart:mirrors (reflection) is available (not tried myself yet), but not in Flutter or the browser. … Read more

GHC.Generics or Data.Data?

GHC.Generics is the modern way and it is much faster than SYB. It however exposes a different approach to generic programming to the end user, so I don’t think that it should be thought of as a direct replacement of SYB, though it does solve the same problems. A good example of how those approaches … Read more

Typescript: Force Default Generic Type to be `any` instead of `{}`

Is it possible? (Without changing the function calls obviously. AKA without a().) Yes. I believe in your case you would do var a = function<T = any>() : T { return null; } Generic defaults were introduced in TS 2.3. Default types for generic type parameters have the following syntax: TypeParameter : BindingIdentifier Constraint? DefaultType? … Read more

Serializing Map with Jackson

The default map key serializer is StdKeySerializer, and it simply does this. String keyStr = (value.getClass() == String.class) ? ((String) value) : value.toString(); jgen.writeFieldName(keyStr); You could make use of the SimpleModule feature, and specify a custom key serializer, using the addKeySerializer method. And here’s how that could be done. import java.io.IOException; import java.util.Date; import java.util.HashMap; … Read more

What is Vec?

It means “Rust compiler, infer what type goes into the Vec“. And it is indeed analogous to the unused variable in Python (and in Rust itself), in that it represents a placeholder for a type, like it can represent a placeholder for a variable name. You can find an explanation in The Rust Programming Language … Read more

How do closures infer their type based on the trait they’re required to implement?

It seems to be a glitch. The Rust-analyzer LSP is able to infer what the type is supposed to be, but for whatever reason the compiler can’t. From what I can tell, this code doesn’t compile on any version of Rust, and cannot be automatically fixed with cargo fix. Interestingly, the compiler does seem to … Read more

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