Questions tagged [generics]

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

Filter by
Sorted by
Tagged with
3
votes
1answer
54 views

Generic Scanner(System.in) Parsing

Often end up using a Scanner to grab some simple input and often when dealing with Number input it can result in a lot of little ...
2
votes
2answers
85 views

Generic Object mapping function

I implemented as an exercise a function which maps over object values in Typescript, and I am truly horrified by my type annotations. The function: ...
4
votes
2answers
118 views

C++ Generic Callback class with removable listeners by unique id

I'm quite new to the STL. Does this make sense? Is there a better way of removing the listeners instead of using shared_ptr while keeping the code short and simple? Is there something in the STL to ...
2
votes
1answer
37 views

Dynamic generic array list implementation in C99

As an exercise to get to know C a bit more, I decided to implement a dynamic array implementation in C99 with generic support. Everything is implemented with series of macros. The array_list struct ...
2
votes
1answer
113 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
0
votes
1answer
44 views

Making a generic web API controller when using multiple tables with similar fields

I have been trying to refactor my code since I found I've been doing a lot of copying and pasting to implement the logic of the web API controllers. Here's how the controllers looked like before ...
0
votes
1answer
64 views

Exists Method Implementation for Multidimensional Array in C#

To determine whether the specified array contains specific element or not, Array.Exists can be used if the given array is one dimensional. I am attempting to implement ...
0
votes
0answers
39 views

Various type Tuple flatten tool implementation

For some reason, I am trying to implement a various type tuple flatten tool with the following requirements: The nested Tuple object ...
2
votes
1answer
169 views

Two Dimensional Array to Markdown Table Converter Implementation in C#

I am attempting to implement a converter which can convert two dimensional array (such as string[,]) into markdown table. The experimental implementation The ...
1
vote
1answer
48 views

Generic Class for a GSON LinkedHashMap

I originally posted this on Stack overflow and was told to post it here, so here it is. Here's the stack overflow question: https://stackoverflow.com/questions/66528393/generic-class-for-a-gson-...
1
vote
1answer
69 views

ForEach Methods Implementation for Multidimensional Array in C#

I am working with System.Array and I found that the input parameter of ForEach method ...
0
votes
1answer
43 views

Divide a 3D matrix into multiple smaller 3D matrix

I'm trying to build an extension method that will allow me to subdivide a huge array into much smaller ones. My current code is the following but it still takes about 2s to generate with an array of ...
5
votes
1answer
92 views

Generic Queue in C

I'm implementing a generic (ie. void *) queue in C. I believe I have a working version but I'm looking for two things: Do any subtle bugs pop out to the ...
1
vote
0answers
104 views

A Generic Two Dimensional Data Plane with Common Math Calculation Build-in Methods in C#

This is a follow-up question for A Generic Two Dimensional Data Plane with SubPlane Method in C#. Thanks to aepot's answer. I am trying to implement a series methods to enhance the ability and ...
1
vote
1answer
109 views

ConvertAll Methods Implementation for Jagged Arrays in C#

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C# and ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up. Besides the ...
1
vote
1answer
72 views

ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C#. Thanks to aepot's answer and Olivier's answer. In order to match the usage of the build-in API <...
9
votes
2answers
178 views

ConvertAll Methods Implementation for Multidimensional Array in C#

I am trying to perform some conversions with multidimensional array in C# and I have checked the discussion ConvertAll and 2-dimensional arrays. I found that ...
1
vote
1answer
121 views

A Generic Two Dimensional Data Plane with SubPlane Method in C#

This is a follow-up question for Generic Two Dimensional Data Plane with Manipulation Methods For C# and A SubPlane Method for Generic Two Dimensional Data Plane in C#. Based on iSR5's suggestion, in <...
3
votes
0answers
585 views

View Binding with Base Classes

UPDATE: After getting "a kind of" affirmation from various platforms( my discussions on twitter, reddit, other stack overflow posts,etc) I have written an article on this style of view ...
5
votes
2answers
475 views

Java generics with wildcard vs non generic List to deal with non generic data

There is a problem on Exercism Java track that requires writing a function to flatten an arbitrarily nested list to a flattened list without null values. For Example input: [1,[2,3,null,4],[null],5] ...
3
votes
2answers
105 views

A SubPlane Method for Generic Two Dimensional Data Plane in C#

This is a follow-up question for Generic Two Dimensional Data Plane with Manipulation Methods For C#. Thanks to cliesens's and Rick Davin's detailed answer. Moreover, the mentioned ...
5
votes
1answer
135 views

Best Practices Generics in Typescript

I'm wondering and actually playing in typescript playground with generics functions. The question is, is the code below readable? If not what kind of approach I could use to make it more typescript ...
6
votes
2answers
126 views

Simplify Generic Method

I am writing a GenericDeserializer for Apache Kafka. My class implements IDeserializer<T> from Confluent.Kafka.Net package....
6
votes
3answers
149 views

Generic Two Dimensional Data Plane with Manipulation Methods For C#

I know that there is a generic data structure System.Array could be used to create customized type array. I want to focus on the two dimensional data structure that ...
0
votes
3answers
122 views

Using “Generics” to implement “Unit Of Work”

I need to design a generic "Unit Of Work", basically so that I can "change the context of the Database" only changing the implementation of ...
6
votes
0answers
113 views

C# Generic high performance vectorized math operations

I'm writing a library which simplifies the usage of intrinsics in C#. It's a generic library which supports all numeric types. The goal of this library is to perform these operations at the highest ...
6
votes
1answer
245 views

Simple generic cartesian product in C++

The idea is to take a sequence of sequences (of the same type) and use tuples of [iterator, current index, sequence size] to keep track of the current state, such ...
4
votes
3answers
201 views

Type-independent vector in C

I wanted to create a vector that can be used for different types, as generics do not exist in C. I came up with an implementation that maintains a buffer on the heap and reallocs itself when the ...
3
votes
1answer
96 views

Bubble Sort In C++

I'm learning modern C++ and also algorithms, and am doing some practice by coding up some simple algorithms. Also trying to use templates whenever possible as I'm quite unfamiliar with generic ...
3
votes
1answer
65 views

Different versions of the Operate method

I have code that basically is the same, but depending on the number of arguments you provide (up to 5), it will operate with them in a very repetitive way. I have the feeling that this can be ...
4
votes
1answer
212 views

Representation of data record for an employee (generic method vs design pattern)

preface: I have a part of my code that is repeated more than once and I want to create a generic method or follow a design pattern to make the code cleaner. What I'm trying to achieve is: I have a ...
3
votes
2answers
318 views

C# One type to represent multiple types (including generics)

Our monolithic WinForm application is getting a face lift. One current challenge that we are restructuring how we setup events. I rolled my own event manager class to handle the subscriptions and ...
2
votes
0answers
85 views

Custom MediaController with full screen video image option

I have overridden setAnchorView() of MediaController class to display full screen option icon using below code.The code seems to be working fine in devices I tested but I have few doubts for which I ...
2
votes
0answers
588 views

Generic RecyclerView Adapter in Kotlin

I've just finished implementing a Generic RecyclerView adapter in my Android app, written in Kotlin. BaseAdapter.kt: ...
2
votes
0answers
119 views

Making 90% similar code for 20 different objects

Basically, I have 20 very similar objects and most importantly I want to do the same thing for all of them. This is the ImportProcessor class for ...
3
votes
1answer
246 views

JSON serializable string enum in C# with generic JsonConverter

How can StringEnumeration be changed in the code below into a generic class, so that ConsensusState wouldn't need the ...
5
votes
1answer
70 views

Double LinkedList Deep Copy in Kotlin with Generics and Thread Safety

Goal Return a deep copy of a double LinkedList. Each node also contains an additional random pointer, potentially to any node or null. Code to start ...
4
votes
1answer
616 views

Generic solution to Hibernate's CriteriaQuery

I've created a little class which helps me to generalize many query cases. I have a DbService and couple methods in it. Can you please take a look at it and share some criticism? The usage of that ...
4
votes
2answers
161 views

Solution of class design issue of generic of restricted type

I am developing a statistics library in .net. I have developed a Set<T> data structure. Now, I want to derive a data structure named ...
1
vote
2answers
113 views

Building a Word document containing two different tables

I am trying to generate a Word document with two different tables inside it. For this purpose I have two similar methods where I am passing word document reference and data object and table to the ...
2
votes
0answers
45 views

Generic Graph Traverser

I have built this Generic Graph traverser, I have this implemented with DFS, I feel it will work equally fine with BFS too. What do you think of this implementation? I want help in reviewing the <...
2
votes
0answers
18 views

Actions component in Angular

I have an action bar component. It helps do the CRUD operation for different component. Its only job is emit events. The emitted events are listened by the caller component. I am using a switch case ...
2
votes
1answer
50 views

Variadic template with function argument

I am trying to develop an ECS registry. How would you improve this ? First disadvantage comes to my mind is using lambdas might be expensive, however I was not able to replicate functionality using F&...
-1
votes
1answer
56 views

Generics for varied option parameter in C# [closed]

I have an app in which I want to create multiple configurable parallel workers. The configuration is done via an "options" parameter because I want to have an interface that requires Run(options) ...
4
votes
1answer
94 views

Write a lock free singleton factory using generics in c#

I am writing a generic CacheProvider factory which contains a concurrent dictionary to keep the "Named" cache objects (a custom implementation of memory cache based on concurrent dictionary) to be ...
2
votes
2answers
174 views

C# - Reapply the manipulation of JS Object in .Net Core

IMPORTANT: I made another version with some improvements: Version 2 Since some months ago I disagree with the native/code methods to manipulate dynamic or ...
11
votes
5answers
1k views

Generic Heap Implementation in C#

This has been done a thousand times on here already, but here's another binary heap implementation. The implementation is generic in terms of heap elements, allows for injection of any type of ...
8
votes
5answers
3k views

Generic linked list implemented in pure C

Recently i added such generic list in github and i would like to get some feedback. Here is a link to the code in github: https://github.com/MartinChekurov/Generic-Linked-List GenericList.c ...
2
votes
0answers
72 views

Generic search service to filter entries in lists

I'm in the process of implementing a fully generic service to filter out entries (of any type), which are contained in a ICollection. As it is generic, without any ...
3
votes
0answers
920 views

Generic CQRS Query handler with custom return type

I am trying to build a generic query handler using the MediatR (v8) library. Let's jump to the code: First of all I have an abstract query class like this: ...

1
2 3 4 5
10