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
2
votes
0answers
56 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 ...
2
votes
0answers
35 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: ...
8
votes
4answers
132 views

Multi-merge algorithm in C++

As you know there is an algorithm in C++ standard library called std::merge, that merges two sorted ranges into another range. I try to write another merge (called <...
2
votes
0answers
47 views

Reduce repetition in these Redux CRUD actions

My React application manages some entities. I'm using Redux (with redux-thunk) to manage the application state. I've created a RESTClient based on Axios: ...
3
votes
1answer
83 views

Resource manager class with basic dependency handling in java

Updates: I kept the original code here, while performed some changes on my machine, including: fixed the incorrect return documentation for clear() made the ...
0
votes
1answer
40 views

Convert generic class into XML string of specific structure

There is a need to have a specific structure of XML string when interacting with 3rd party system. Here are two examples: ...
3
votes
1answer
58 views

Check all permutations of generic type parameters

I have a function that takes an object ("token") and three additional parameters of different types ("obj1", "obj2", "obj3"). The object "token" has an 'IsSatisfied' method that may take none, 1, 2, ...
1
vote
0answers
78 views

Generics and aggregated evaluation of validation rules

I have a custom system for data validation; it handles anything from method parameters, return values, objects, etc. The core of this system is IValidationRule and ...
0
votes
1answer
62 views

using a cast in an overriden equals method should I use generics and if so, how? [closed]

here is my issue when trying to override my equals method. this is what I have currently ...
3
votes
1answer
165 views

Rest Api with generic crud operations

I am learning how to create a rest api in which I've decided to use generic for crud operation. I am attaching the code which I have written so far. Please have a look. Thanks for the review in ...
4
votes
1answer
34 views

Use a delegate to assess equality

I have built my own generic class to implement IEqualityComparer(Of T), which takes a delegate as an input for the constructor. This delegate takes two objects of ...
2
votes
1answer
610 views

Angular Rest API generic service and implementation service

I'm wondering if there's a better way to write the ApiService and the CategoryService so that CategoryService is basically just a call to extend ApiService with the string 'category' and the base type ...
4
votes
2answers
70 views

Generic wrapper for single value or array of values

I'm writing a chart.js port for c# blazor (you can find it here) using C# 8.0 with .NET Core 3 (latest preview). In chart.js there is this thing called indexable options. It let's you use either a ...
5
votes
2answers
246 views

Generic Extension Method To Count Descendants

I've created a extension method to count every available descendant starting from a single, given key. The data is a flat list, there's is no hierarchical structure. (Well, not entirely true. There ...
9
votes
2answers
249 views

Immutable builder and updater

There aren't enough questions about creating immutable objects... so why not try it again with another approach. This time, it's a builder that maps properties to constructor parameters. Properties ...
2
votes
1answer
67 views

A Simplistic Finite State Machine Generator

I have designed a compile time Finite State Machine generator. I have chosen to use some of the features of C++17 such as parameter pack expansion, fold expressions and lambdas to keep the complexity ...
6
votes
1answer
80 views

Distinguish between different types of log items in a dictionary by their key

My logging adapter is using a dictionary for storing data that is passed from middleware to middleware. It is a one-liner: ...
2
votes
1answer
72 views

Implementation of Generic Binary Tree Code

I'm in the process of independently learning Generics as a way to build on a college assignment for Binary Search Tree. I've completed this program without Generics first and now I've converted over ...
4
votes
2answers
135 views

Creating custom objects with custom properties using generics

I have two base classes: City and Building: ...
4
votes
0answers
82 views

Generic Macro Generated Interval Heap in C

When I saw this amazing data structure I couldn't stop myself from trying it! I first sought resources such as this and an article about it here. It basically works as a Max-Heap and a Min-Heap at the ...
3
votes
1answer
55 views

Range validator for multiple types

I have an existing overloaded set of functions that I cannot change and need to be tested: ...
9
votes
2answers
135 views

Generic data structures in C

I'm new to C, and I thought a great way to learn would be to implement some generic data structures and algorithms. So far I've implemented a linked list and a dynamic array. Both are generic, the ...
2
votes
1answer
122 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...
6
votes
1answer
163 views

Enumerate all members and types with specific attributes

I have a use-case where I need to retrieve all members with specific attributes in the class and interface hierarchy - I usually need the first match and apply its rules to child members. The built-in ...
6
votes
3answers
340 views

Calculating time windows for entities

I have made some code that operates on multiple entities and creates 'time windows' for them. Basically, the entities will contain states, usually in boolean or int. They will be timestamped and in ...
3
votes
2answers
59 views

Generic function that accepts both Actions and Func's as parameters

I've created a generic try catch I can apply throughout my code so I'm not repeating myself. ...
-4
votes
1answer
57 views

Generic Custom STACK Class for Hanoi Problem in C# [closed]

I have created a custom class (Generic) in C# for the Hanoi problem. and I am not sure I did the correct thing. ...
2
votes
2answers
70 views

Creating keys/names from interfaces to avoid strings

There are many APIs that require some kind of a string key/name. I usually try to avoid using raw strings and prefer to use ...
5
votes
1answer
84 views

Enum for handling network request errors in Swift

I'm working on a new API written in Swift 5 and I wanted to play with the new Result. I wanted to know what you guys think about this syntax: ...
1
vote
0answers
197 views

Spring (boot) MVC Abstract Controller

I'm writing an application that will end up with a set of standard CRUD operations for a bunch of object types, and I thought it would help simplify things if all the separate controllers had some ...
3
votes
0answers
43 views

N-Queens problem using other pieces using Go

I wrote a solution to a problem based on the N-Queens problem which should use more pieces than just queens. Problem is it's very slow, it probably has to do with how I modeled data and my lack of ...
0
votes
1answer
79 views

Generically call static methods

I currently have two (core) classes : ...
1
vote
2answers
124 views

Typed properties in Java

I tried to build a "typed" property system in Java and this is what I came up with: first the class Properties that any class can use as an attribute (demo code in the end). ...
1
vote
0answers
25 views

Calculate mean of vector primitive numerical values generically

I'm trying to write a generic mean function for all values within an Vector of generic numerical primitive type. Could the following implementation be possible ...
3
votes
1answer
88 views

Generic Macro Generated Hashset in C

The Hashset uses open addressing, linear probing and Robin Hood hashing for handling collisions. It comes with insert and remove ...
2
votes
1answer
299 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
0
votes
2answers
86 views

Generic function, which populates a collection based on collection interface implementation

As the above title states I have a function that I use to populate a collection's status names, currency names and other information that I do not store in the database. This is my function: ...
3
votes
1answer
114 views

Map, which contains biomes, which contain landforms, which contain tiles

I am trying to model this: a Map can have multiple child of type Biomes and no parent a Biome can have multiple child of type Landforms and a Map as its parent a Landform can have multiple child of ...
3
votes
1answer
116 views

Rust closure to be called on a cache miss

The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash ...
0
votes
0answers
35 views

Templated JSON parsing methods that work with an element or elements array

Consider the following two Java methods. The first takes a JSON string representing one element, the second representing multiple elements. gson.fromJson() can be ...
2
votes
1answer
78 views

Swift: arrayToTree() where array contains int and nil

I am learning tree on Leetcode. Need to prepare the testing data. It is easy to convert the array to an organized node, where its elements are integers. such as ...
3
votes
1answer
180 views

AVL height-balanced binary search Tree and Dictionary in C# v2

Mostly as a learning exercise, and partly as I thought it might be useful, I have written an implementation of AVL trees ( https://en.wikipedia.org/wiki/AVL_tree ). An AVL tree is a height-...
3
votes
0answers
49 views

Generic router in Rust

I am trying to make a router in Rust using Rocket.rs. I'd like to devise a way to use a default router for my more simple db tables that don't require different logic, to prevent rewriting the same ...
2
votes
1answer
50 views

Batch downloading to file or memory

This is likely my first useful piece of Rust code. Planning to crate-ify it. It works. ...
3
votes
3answers
289 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
1
vote
1answer
699 views

Implementation of Generic SQL Data Reader

I am using below virtual method to read the data from SQL Data Reader like: ...
0
votes
1answer
69 views

Recursive fluent builder

Problem statement I have entities whose relations form a graph. As an example, let's imagine Users and Groups. Each user has a <...
1
vote
1answer
257 views

Fisher-Yates shuffle Java implementation

This is my attempt at an implementation of the modern Fisher-Yates shuffle in Java. I'm not sure if it can be made more efficient, but I did my best to make it as simple as possible, and I learned how ...
2
votes
1answer
39 views

Numbers adder via generics

This method add all numbers in list and return it as double ...
0
votes
1answer
29 views

Program to check if heap order is correct or not

There is a Java program to check if a Heap (Min) is in the correct order. Heap Order means the parent is less than both left child and right child. ...

1 2 3 4 5 9