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

3
votes
2answers
51 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
2
votes
3answers
80 views

Related classes around generic types

I'm wondering if this code can be simplified. I'm less than thrilled about the fact that I repeat the Draw method in both CatModel and DogModel. For that matter, I'm not real happy that that method is ...
5
votes
1answer
161 views

Early Binding with Generics

I have a class which takes the method address and arguments, and executes it later when told to do so. ...
1
vote
2answers
73 views

Implementing a generic class and choosing a collection based on a type

In this topic here I have aksed for help to sort out an error while creating a generic class whose method can return a different collection given a type. I received the answer and working solution but ...
8
votes
1answer
247 views

Generic domain independent Monte Carlo Tree Search methods library

I've written this small generic library for the purpose of my Bachelor’s thesis. It's fully functional and unit tested and I want to get as many opinions as possible regarding overall code quality ...
4
votes
2answers
81 views

App settings helper

The helper should be able to set a default value if the value can't be fetched with the provided key. There is also a bool that will throw an error if the key value or the default value could not be ...
4
votes
1answer
56 views

Sorting a linked list using mergesort

This sorts a linked list using mergegort. Can you please critique my code and provide your thoughts on where I should improve my code? ...
0
votes
0answers
141 views

Generic method to pass lambda expressions performed on DTO's to Entity Framework

The following are generic methods that I use to perform lambda queries on DTO objects. The main method applies the expression to entities and returns DTO objects mapped from the entities (entities ...
6
votes
0answers
100 views

Efficient generic type conversion between numeric types in F#

It's easy to write a function that adds two ints in F#: let add x y = x + y Actually it's the same as: ...
6
votes
3answers
278 views

Generic getting single value from DB in C#

Few months ago I posted my code Getting a single value from the DB. I implemented suggested changes and this is how it looks like right now: ...
4
votes
1answer
58 views

Generic Constraints and new()

I have have attempted to use generics and constraints to create functions that retrieve and save data from a number of similar objects. Each of these objects describe their own properties. When I use ...
5
votes
2answers
128 views

Recursively merge dictionaries with generic types in C#

I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
-1
votes
1answer
64 views

Singly linked list with generics and comparable data [closed]

I am currently reading about the thread-safe implementation of a linked list. Although I implemented this linked list while keeping in mind the issues from the first code review (Binary Tree). I would ...
2
votes
1answer
784 views

Cached-object Store c# with Redis client for persistent storage

I have written a Cached-Object store with a Redis Client for persistent storage. The application that is going to use this is a heavy read application with the occasional write. I assume that entire ...
1
vote
1answer
75 views

System to handle the short lived async task

I'm developing an application in which there are many short-lived tasks which are run in separate threads. I've developed a generic and reusable system to handle such a requirement. The code snippet ...
4
votes
1answer
54 views

Event driven timed I/O

The following code is used to access a shield which converts settings written over I2C to Servo output. I make use of the MRAA library since that's the default supported by my hardware. To prevent ...
6
votes
1answer
330 views

JSON serializer using generics rather than System.Object

I recently created a custom static class in C# to encode, hopefully, any object it is given (or collection of objects), because I was, at the time, unaware of a native C# library that did the same ...
1
vote
1answer
90 views

Initializing local variable to generic interface

Below is my working code written as an exercise in wildcards in generics and Java 8 type inference. My question will be about the commented line in union() method. ...
5
votes
2answers
55 views

Getting a set of subscribers from a subscriberMap

In my Java event bus project, I have a private generic method that retrieves a Set<Subscriber<E>> from a private ...
5
votes
2answers
236 views

Generic method to split provided collection into smaller collections

First time writing a generic method here. Input a List<T> and an int value and output a ...
6
votes
1answer
98 views

Java 8 unit test for third-party data feeds

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
10
votes
2answers
408 views

Optimize a generic foreach method that converts Datatable to my object using Reflection

I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
7
votes
4answers
299 views

Typed NSUserDefaults

I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to ...
0
votes
2answers
127 views

Implementation of peak finder

I implemented this peak finder for practice. I have tested it. Everything looks pretty good to me. Please let me know if there is any improvement I can make. Peak Finder Let input be an ...
4
votes
0answers
199 views

Recursive flattening of Swift sequences

In Flatten to get all child controls of certain type in a UIView, methods were discussed to recursively flatten a tree-like structure in Swift, resulting in an array of all elements. Motivated by ...
2
votes
1answer
68 views

Generic classes with inheritance/equals/comparison operators

I would like to greatly reduce verbosity of following code fragment. What I'd like to do: Reduce number of occurrences of MaterialRangedParam<Value> and ...
3
votes
1answer
399 views

Java Generics - Write a generic method to find the maximal element in the range [begin, end] of a list

I'm a Java beginner, going through the Generics Questions and Exercises in Oracle's The Java Tutorials. Here's my solution to #8: Write a generic method to find the maximal element in the range ...
11
votes
0answers
229 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
6
votes
2answers
388 views

Generic NSMapTable replacement written in Swift

This is my attempt at writing a generic NSMapTable with weak keys and strong values (after your feedback I'll be trying to write Strong-Key/Weak-Value and ...
5
votes
1answer
72 views

Mergesort a LinkedList

I have made an attempt to write the mergesort routine on a LinkedList in Java. It will be great if somebody can review my implementation and point out the issues ...
2
votes
1answer
118 views

Web API controller to get details of a travel plan or a leave request

My web API has 3 controllers for get, post and users CRUD. I named it as DetailsControllor, FormControllor and ...
2
votes
2answers
49 views

Converting a DropDownList retrieval service to generics or delegate methods

mappingService below is actually just Automapper. I have a wrapper around it so that I can inject it. I want to refactor the following code to be cleaner: ...
2
votes
0answers
48 views

Implementing insertAt for both [a] and [(i,a)] lists

I've implemented generic insertAt function which inserts value to a list independently from is list indexed or not. Here are some examples: ...
2
votes
0answers
55 views

Advice on modelling with generics in Java

Use Case The third party library that I am working with implements its data model in this fashion. ...
3
votes
1answer
183 views

Fully Generic C++ Stack Implementation Without Lists, Arrays, or Vectors

I'm trying to write a fully generic Stack in C++. I'm not sure if this is the best way to do this. Right now I know that the Pop method needs improvement since ...
1
vote
1answer
440 views

Creating a Generic Template Interface/Class and injecting into another object

I would like to create a generic template class for my document processor. Assuming the template has a source file path and a "content", here's what I came up with: Template ...
8
votes
2answers
313 views

Generic queries and handlers without reflection

I'm trying to implement generic queries and handlers so that I can make requests with simple syntax, like this: ...
1
vote
1answer
43 views

A banded interpolator, for any type and any interpolation method

This is an extension of my Attributes system I wrote about in these questions: Lvl 1 upgradeable attributes Lvl2 upgradeable attributes It is unrelated to the core functionality under review in ...
3
votes
2answers
340 views

Immutable Queue in Java using an Immutable Stack

I am new to this Immutability concept and I have some coding experience in JAVA. Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
5
votes
1answer
92 views

Self-made LinkedList and Node

I have recently made two kinds of linked lists in Java. I know that there is one with generic and one without. However, what I am really concerned about is which style should be used mostly (or which ...
4
votes
3answers
2k views

Generic sum method for a Collection<Number>

While answering this question, I wanted to use a generic sum of Collection function. Java doesn't have a native method, so I wrote one. There are a couple things ...
10
votes
3answers
371 views

Simple Generic output for Deserializer

Lately I have been learning about serialization so I decided to write a little helper class for my application to make it easy to use this feature in multiple places. I actually mixed some generics in ...
3
votes
3answers
433 views

Implementing a singly LinkedList and IList interface

I have implemented a LinkedList in C#. What would you change/make better? What naming conventions are misused? What would you add? Some of my ideas are to make it ...
3
votes
2answers
96 views

Nullable Generics - Implementing SequentialSearchST in C#

For learning purposes, I am implementing certain code from Sedgewick & Wayne's Algorithms, Fourth Edition. Because of language features, a direct translation doesn't seem possible. For example, ...
0
votes
1answer
111 views

Does Java need an Observable object with generics?

This is the follow-up question from here. This is an Observable class similar to java.util.Observable. The difference is that ...
3
votes
2answers
748 views

java.util.Observable but with generics to avoid casts

This is an Observable class similar to java.util.Observable. The difference is that it uses generics to avoid casts. The ...
1
vote
2answers
140 views

Parse File or String input in a uniform way: Is it possible with Generics?

I have a Parser class which creates a collection of String pairs, parsed in the format key=value. ...
10
votes
1answer
890 views

VHDL mux in need of generics

I've built a multiplexer which takes 2 inputs: one array of std_logic_vector and one std_logic_vector to select the correct ...
5
votes
2answers
113 views

Applying TrimSideSpaces() method to multiple string properties

I am looking for generic ideas and guidelines of how to improve the style of my coding and make it more readable and robust. ...
6
votes
3answers
1k views

How can I make this StringToCollections method more generic?

I am new to C# and I have big functions that receives the following arguments: (Package inPackage, string materialIDs, string functionIDs, string companyIDs) ...