Category "generics"

TypeScript function that works on all numerical array types

I am trying to write a function that works on all of the JavaScript array types, e.g. on number[], Float32Array etc. It should return the same type that it gets

Type erasure Generics

An error occurs at new T[5] during compile-time saying => error: generic array creation and according to my understanding, the array is created during compil

The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'TableClient.QueryAsync<T> [duplicate]

I'm using 12.0.0-beta.6 of the Azure.Data.Tables nuget package. When I try to invoke TableClient.GetQueryAsync it gives me the error: "The typ

Android generic Gson.fromJson() conversion with coroutine and flow

I am making generic classes for hitting otp api.anybody can use otp section just have to pass request ,Response class and url and all will be done by this otp s

How do you implement a trait for T where T: Foo OR Bar

In rust, you can automatically implement a trait for any type that implements some other combination of traits. Ie: impl<T: Foo + Bar> SomeTrait for T {

What is struct Cleaner <T*> mean?

What is struct Cleaner <T*> mean? Is it specific the second Cleaner can only accept the type of pointer? what is the terminology of this usage in C++? te

How to create generic method in Go? (method must have no type parameters)

Golang 1.18beta supports generic, I want to add an extension method on a generic slice. e.g. a map function is defined as this: func Map[E, V any](slice *[]E, i

In a Java interface, is there a way to return an enum nested in a generic type?

I'm looking for a way to return an Enum type nested in a Generic class. Here's what I mean: public interface MapperClass<E, D> { D entityToDto(E enti

typescript generics class, method parameter and method return type

I have this function function getCollection<T>(collectionType: T): Collection<T> { return new Collection<T>() } and in Collection class I h

Function type cannot have type parameters

I am trying to write a sample program to try and implementing the a data structure using go generic proposed in go2. As part of this I want to define a iterator

How to use a generic session with Actix and Paperclip?

I've created a server using Actix Web which has authentication support. Now I want to add an OpenAPI Specification using paperclip. Normally you only have to ad

Is there an idiomatic way to have a generic over T, &T, Box<T>, Arc<T>, and so forth, where T implements some trait R?

Let's say you have a structure that you want to be a generic over time type T, so long as that type implements some trait R. That's pretty trivial: trait R {

Map Typescript generic array

Suppose I have an object with a static set of keys, and then a type specifying a subset of those keys as a static array: const myBigStaticObject = { key1: ()

How to convert String to Generics in java

I have a class similar to this: public class Car<T> { private T model; private CarBodyParts body; } public class CarBodyParts { private Integer

Generic function typedef in C - how to get rid of initialization warning?

I'm experimenting with generic-like code and I have a function like this (a lot of not relevant code removed): typedef uint8_t (*struct_converter_t)(void *, cha

Generic function typedef in C - how to get rid of initialization warning?

I'm experimenting with generic-like code and I have a function like this (a lot of not relevant code removed): typedef uint8_t (*struct_converter_t)(void *, cha

How to assign or return generic T that is constrained by union?

In other words, how do I implement type-specific solutions for different types in a union type set? Given the following code... type FieldType interface { s

Facing issue with having generic as return type in Golang

I'm invoking a function from another library whose return signature is defined as under: (*studentlib.Student[StudentResponse], error) Student is defined as: t

Python generic that adds typed functionality to extend existing types incorrectly typed

I am interested in creating a generic to add a fixed functionality to different types in python. I have a semi working solution, but it's tying is problematic.

is there a Generic way to assert type? [duplicate]

I have found myself writing the same function X number of times to get different types of Items out of my go-cache. The duplicate functions ar