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.

learn more… | top users | synonyms

5
votes
2answers
77 views

Using generic types for a custom mapper

I have a method which takes a certain generic object, which basically orders these objects based on a list of tags. Because I want to use this method for multiple objects, I have created a class which ...
13
votes
7answers
968 views

Binary Heap where a comparison delegate is used

I currently have a Generic Implementation of a BinaryHeap. It must be able to maintain it's integrity with elements that may or may not implement ...
2
votes
1answer
73 views

Adding various types of configurable validators to fields

I am currently reworking our entity code generator, that uses JaxB for schema validation, and Stringtemplate for code generation. As we are giving our professional service the possibility to add ...
2
votes
2answers
45 views

Object to return user specified generic types in backend code

The idea is that a user will dynamically edit simple key/value settings that will customize their instance of the application, e.g. the welcome banner text. I am trying to implement everything in a ...
4
votes
3answers
173 views

Automatic computation of mean, standard-deviation, sum, min, max in property

Working on a game I need to record events compute some values about it (the more the better). The twist is, I need to store as little data as possible. Constant (as in O(1)) weight is required. The ...
11
votes
4answers
825 views

Convert a boxed integer to an nullable integer with potentially different type

Given a boxed integer (with a boxed short, int, ...) I want to convert it to an unboxed, nullable type instead. It should be ...
6
votes
2answers
102 views

“Simple” generic inheritance

I'm sure that my intentions are highly erroneous, and I really just want to see what you guys would suggest I do instead. I have a class I made for my game which helps store various values regarding ...
6
votes
2answers
141 views

Accessing properties by name with compile-time typesafety

I've recently answered a question here, where the goal is to mimic some functions from System.Reflection in order to avoid it's direct usage as much as possible, ...
6
votes
2answers
179 views

Generic immutable object builder

I've made an object builder which can create all sorts of classes, it can also create immutable objects. There are 2 requirements that must be met in order for this pattern to work with fully ...
3
votes
1answer
58 views

Making Dependency Property registration strongly typed v2

This is my second attempt to create a strongly typed builder for the Dependency Property. I've improved the two main weaknesses of the previous version which were: Can specify only ...
3
votes
1answer
47 views

Making Dependency Property registration strongly typed

I've been working on another builder, this time for the DependencyProperty because it's object-based. This means that every ...
3
votes
3answers
81 views

Batch save with progress reporting

I reviewed this question that in my opinion uses a not so pretty batch-save so I tried improve it and this is what I came up with. In this more generic solution that allows to reuse it I wanted to ...
3
votes
0answers
48 views

Generic Factory using Function library

Here's my implementation of Generic Factory using Function library. It was created using Function library because I understand that the newInstance method is ...
4
votes
2answers
95 views

Dynamically convert property to different data type

The code finds marked attributes and parses them according to the attribute type. Is it possible to simplify this logic? Is there generic way to do it? Please suggest some way to optimise this code. ...
3
votes
1answer
50 views

Optimal custom operator with generic type constraint for numerical type

I'm implementing (for an article) two custom infix operators: ¿% - to calculate percent of total %? - to calculate the percent ...
12
votes
1answer
569 views

Creating a pipeline operator in Java

I wrote the following as more of an experiment than anything else, but I thought it would be fun to share and maybe get some feedback! Motivation: I started looking at some functional languages and ...
1
vote
0answers
28 views

Generic natural merge sort a linked-list in C

I have a .h file that implements my "generic" by defining LINK_* beforehand. This is an implementation of natural merge sort on doubly-linked lists using log n ...
4
votes
1answer
96 views

Test and implementation of a reorderable data structure that stores number of users (classifiable as per gender, country, etc.) of an Application

I have implemented a data structure that allows storage of number of users of a hypothetical application in a tree-like data structure in nodes as per their classification based on categories such as ...
2
votes
0answers
65 views

Generic wrapper for Alamofire Request's function jsonResponse wrapper

I am trying to wrap a responseJSON function of a Request class of Alamofire because when I send an API request I get a response ...
1
vote
2answers
70 views

Singly linked list RemoveBefore() method

I am trying to implement a singly linked list. What is the most optimal way of implementing a RemoveBefore(ListNode) method? I have done this: Check if node being ...
1
vote
1answer
67 views

Sequence to extend and forget

After receiving some feetback about my previous attempt to create reusable, easily extendable sequence generators I try once again to create such a framework. This time there is no inheritance. Just ...
4
votes
2answers
89 views

Sequence generators not only for potatoes but also for apples and oranges

The last question about sequence generators Growing potatoes in delayed sequences was only about potatoes. I thougt why not make it work with apples and oranges too so I made it generic. The base ...
2
votes
4answers
188 views

Calling a function on an object if not null

Here is code for check null in object: ...
1
vote
1answer
40 views

Generic coverter for fields in class

Here is a simple implementation of generic method that get value from array in class and cast it to a type. ...
4
votes
0answers
75 views

C# cache controller (Followup)

This is a followup to the question: C# cache controller Suggestions taken onboard from previous feedback, and refactoring to shorten the code in the calls to the cache controller by allowing queries ...
0
votes
0answers
100 views

Refactoring duplicate custom service configuration in .NET core

In my current .NET Core project, I want to inject two services into my controllers for dependency injection. I wrote the following extension methods that each takes a ...
1
vote
1answer
104 views

DAO for fetching organizations and departments through a REST API

I have the following class structure: ...
0
votes
0answers
23 views

Filter Stream based on Class, Using Stream in place of Optional

I was reading this reddit post regarding filtering a Stream<T> based on some Class<R>. The author suggested giving ...
0
votes
1answer
93 views

Converting models into a list of ViewModels [closed]

I have the following code: ...
4
votes
1answer
143 views

Abstract factory using generics

I am learning design patterns and I have implemented the abstract factory using generics C#.NET. Is this implementation correct or not? Or is there any SOLID principle violation? ...
1
vote
1answer
42 views

Quicksort implementation equivalent to Collections.sort()

Here is my go at understanding generics, Comparables and Comparators, as well as type bounds. I believe I made it as close to <...
4
votes
3answers
144 views

Concatenating two IEnumerables with a limit

I've been playing around with generators, generics and extension methods in C# (5.0) and wanted to create an extension method for IEnumerable, which would append ...
4
votes
2answers
99 views

TextBoxes for various number types

Is there a way I could somehow have all this classes condensed into one, while keeping the code as clean as possible? They are all doing essentially the same thing, just for the different number type....
4
votes
3answers
166 views

Implementing a generic Queue in C

I wrote a generic Queue that could with work any data type you give it. The Queue can do any the basic operations that you would expect a ...
1
vote
0answers
32 views

Caching generic types statically

Given the need to share several big models throughout an application (web application, the models need to persist between requests), I would like to create a unified cache handler to keep them in ...
2
votes
1answer
79 views

Implementing a Generic Quick Sort With Various Optimizations

I decided for educational purpose to make a generic sort like the one in the standard library as an exercise for my self in learning more about how to do generic programming in C and so I would really ...
3
votes
1answer
44 views

Validation rules with support for immediate termination of processing

I am picking up a code smell from this code and I am not sure of the best way to rid myself of it. I have a validation class that has a function that returns a list of ...
0
votes
1answer
30 views

Generic Int conversion to scalar

I'm new to Scala and I'm trying to write a generic function to convert from Int to any scalar. For example: ...
8
votes
3answers
466 views

Return a key when a function returns true

I've no idea what to call this, so I called it Classify since that's how I use it. Basically, the idea is to pass a ...
1
vote
2answers
109 views

Alternative to using Object and casting in a map

I have the following class which represents a set of properties. ...
7
votes
1answer
122 views

Database abstraction layer for multiple providers

There's been a lot of questions lately about database provider and repository design especially without entity framework or alike. I thought I try myself to create a reusable framework for this kind ...
3
votes
2answers
63 views

C# enumerable property like .Any that accounts for nulls

Brief Description: A generic extension method that performs the same function as IEnumerable.Any(), but does not throw an error when passed a parameter with a <...
7
votes
1answer
100 views

Sum numbers input from terminal

The following Golang code accepts a sequence of numbers (any integer and float type) in the terminal, adds them, and prints the result (sum) to the terminal. Actually in Golang you can't add ...
7
votes
3answers
86 views

Custom collection implementing IList<T> saving current, next and previous element

I'm developing a Tic Tac Toe game where you can change your pawn look Now as You can see it has 2 buttons one for next one for previous, and You can also pick if you want to edit the O or the X ...
9
votes
2answers
425 views

Responding to API requests with much complexity

So having used the SE API multiple times, I like how all responses are in a Wrapper object, and for my own API design I figured it was a good method to follow. Of ...
7
votes
1answer
91 views

HTML-rendering framework for emails

Sometimes I need to auto-generate html-emails. To make this task a little bit easier I created a simple framework that takes care of rendering HTML. Because I'm mainly interested in generating HTML ...
10
votes
3answers
248 views

Structure to ByteArray Extension

I have a need to turn various structures into byte arrays to be sent over serial port to another machine. I created generic extensions to turn any structure into a byte array and from a byte array ...
1
vote
0answers
83 views

Generic Pairing Heap Performance

I have made a generic pairing heap library in C. Pairing heaps are one of the several heap variants with better asymptotic running times than standard binary heaps (others include Fibonacci heaps and ...
8
votes
5answers
130 views

Removing exact instances of elements in one list from another

Basically, here's the problem statement: Given an IEnumerable<T> source and an IEnumerable<T> exceptions, return ...
3
votes
1answer
293 views

A small generic array in C

The generic arrays in C I found on the net used either of these methods: The preprocesser with #define and #include (a lot of ...