Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
0 votes
1 answer
46 views

Correct usage of Java Generics for a simple cache holding objects of any particular type that contain an identifier of any particular type

The Stack Overflow question, I'm trying to create an inMemory database using Collections and generics, presents some code that attempts to use Java Generics for an in-memory cache of objects of any ...
user avatar
2 votes
1 answer
87 views

MongoDB abstraction in Go with generics

I'm working on a new project with go. So I figured I would give this new feature a run (it's fun!). Although, I'm not sure I'm implementing this the way it's suposed to be. I've read the following ...
user avatar
  • 123
1 vote
1 answer
90 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
user avatar
1 vote
1 answer
69 views

JSON save system for Unity

I made a Json save system for my Unity game. I wanted to make something as generic as possible to keep the code DRY. I couldn't find much information online on how to make something generic. Could you ...
user avatar
3 votes
0 answers
79 views

Build the Mountain Car Environment using coupled inheritance and type annotations

This code builds the environment for the standard Mountain Car Problem of reinforcement learning. I'm using Python 3.9 with PyCharm and I'm wishing to use type annotations throughout. I'm trying to ...
user avatar
5 votes
3 answers
405 views

generic implementation of median

Below is a generic implementation of the summary statistics function Median. Discussion of efficient use of std::nth_element and ...
user avatar
3 votes
2 answers
72 views

Generic Observer/Listener implementation in Java

I am working on a personal project in university where I am currently trying to make my own implementation of a generic observer pattern that I can use throughout my project. I would appreciate any ...
user avatar
1 vote
1 answer
50 views

Getting a single result from multiple LiveData objects

I have an Android viewmodel for a Fragment that requires the user to perform multiple tasks. In addition to a LiveData object to track the status of each task, I ...
user avatar
3 votes
0 answers
74 views

Handling boilerplate tasks via service pipelines

Here's a small experiment about handling boilerplate tasks via service pipelines. It's similar to the HTML pipeline but simpler and multipurpose. I've updated the question and this is the 2nd version ...
user avatar
  • 43.8k
3 votes
1 answer
67 views

C Typed Vector that implements type-safety, encapsulation and lazy initialization

C Typed Vector I wasn't happy with the various dynamic array / vector implementations in C, so I made my own. In general, I'm not the biggest fan of C-preprocessor madness, but alas for this ...
user avatar
  • 171
7 votes
5 answers
917 views

Checking whether a string is a permutation of a palindrome in C++20 - follow-up

This post is the follow-up of Checking whether a string is a permutation of a palindrome in C++20. So, what's new? Well, nothing else except that the procedure is now generic and accepts all ...
user avatar
  • 25.3k
1 vote
0 answers
85 views

LazyList[T]: Class/ Decorator for constructing a list from a Generator - generating and caching values only when needed

I made a LazyList class that can wrap an iterable (list, generator etc.) and turn it into a MutableSequence (like ...
user avatar
  • 1,998
0 votes
1 answer
37 views

interface different usages issue for two or more different implementations

I am writing a small micro-service in typescript with NestJS. This microservice is responsible of giving a user access to one of our company's systems trial access. At first I used hubspot integration ...
user avatar
0 votes
1 answer
96 views

Generic Base Repository implementation with Unit of Work in C#

I have seen a lot of Repository pattern implementations with Unit of Work. The simplest way of implementing this I came across is using hard-coded repos (such as this one), while the way recommended ...
user avatar
1 vote
2 answers
76 views

Retrying a RestRequest

I wrote a method that lets me retry RestSharp requests when a specific exception is thrown. Here's the code for that method: ...
user avatar
4 votes
2 answers
807 views

Method for create a copy of List<T>

I created a method to return a copy of List<T>, basically I convert the List<T> into an array ...
user avatar
1 vote
1 answer
140 views

Generic doubly linked list in C

I have implemented generic doubly linked list in C language in which you can store any data type you want. Just like in C++ and Java, where a list can store any data type, like - string, int, long, ...
user avatar
1 vote
1 answer
42 views

Stream that computes running median value

I was solving a DSA question, running median in a stream. And I decided to design my own stream class with additional features. ...
user avatar
3 votes
1 answer
80 views

A predicated version of std::for_each

For reasons, I want to implement a predicated version of std::for_each. I know that, in C++20, this is made somewhat redundant or less useful, as we can use ...
user avatar
  • 1,925
3 votes
1 answer
230 views

Quicksort using generics in java

The goal is to have a function that can sort a series of all object types that implement the comparable interface. I'm not trying to improve the performance of the sort. I'm only trying to optimize my ...
user avatar
  • 131
4 votes
3 answers
329 views

FIFO array/queue

I'm new to programming and was tasked with programming a generic circular FIFO queue, without using anything but an underlying array and self-programmed methods. I still don't know how to approach ...
user avatar
0 votes
0 answers
35 views

Map over an Object's keys/values, returning a new Object, ala Array#map

In the process of migrating an ancient CoffeeScript codebase to TypeScript, I'm also attempting to abandon lodash/underscore.js-alikes in favour of modern JavaScript-standard-library-features (or ...
user avatar
0 votes
1 answer
74 views

How to save/get different type of data with less duplicated code

description: I'm using thrift to save and get data by filter. The data have many types, and the types may increase in the future. So I use ...
user avatar
4 votes
0 answers
118 views

A safe type-erased Fn Pointer in rust that can be used to call associated and regular function

I am implementing a callback method to replace the use of generics. For maximum performance, it is not allowed to use Box and I also don’t want to use ...
user avatar
  • 141
4 votes
2 answers
175 views

CGI script that reads or writes its height and weight configuration

UPDATES: I'm looking for an answer that can answer the questions listed in the post. Moreover, this answer will not only continue my way of thinking, but also give feedback based on it. It's just like ...
user avatar
3 votes
1 answer
197 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 ...
user avatar
2 votes
2 answers
255 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: ...
user avatar
  • 121
4 votes
2 answers
424 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 ...
user avatar
  • 160
2 votes
1 answer
131 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 ...
user avatar
  • 145
2 votes
1 answer
191 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
user avatar
  • 269
-1 votes
1 answer
403 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 ...
user avatar
0 votes
1 answer
474 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 ...
user avatar
  • 3,302
0 votes
0 answers
55 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 ...
user avatar
  • 3,302
2 votes
1 answer
342 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 ...
user avatar
  • 3,302
1 vote
1 answer
70 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-...
user avatar
1 vote
1 answer
90 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 ...
user avatar
  • 3,302
0 votes
1 answer
53 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 ...
user avatar
5 votes
1 answer
240 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 ...
user avatar
  • 557
1 vote
0 answers
106 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 ...
user avatar
  • 3,302
1 vote
1 answer
145 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 ...
user avatar
  • 3,302
1 vote
1 answer
76 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 <...
user avatar
  • 3,302
9 votes
2 answers
276 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 ...
user avatar
  • 3,302
1 vote
1 answer
125 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 <...
user avatar
  • 3,302
3 votes
0 answers
990 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 ...
user avatar
5 votes
2 answers
888 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] ...
user avatar
3 votes
2 answers
111 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 ...
user avatar
  • 3,302
5 votes
1 answer
234 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 ...
user avatar
  • 153
6 votes
2 answers
164 views

Simplify Generic Method

I am writing a GenericDeserializer for Apache Kafka. My class implements IDeserializer<T> from Confluent.Kafka.Net package....
user avatar
  • 286
6 votes
3 answers
160 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 ...
user avatar
  • 3,302
0 votes
3 answers
145 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 ...
user avatar
  • 202

1
2 3 4 5
10