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

0
votes
0answers
10 views

Repository pattern done right

The following IRepository pattern ...
1
vote
0answers
25 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
0answers
68 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
32 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
68 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 ...
3
votes
2answers
84 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 ...
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. ...
3
votes
0answers
65 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
98 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
93 views

DAO for fetching organizations and departments through a REST API

I have the following class structure: ...
0
votes
0answers
22 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
2answers
127 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
40 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
98 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
127 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
69 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
40 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
27 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
463 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
89 views

Alternative to using Object and casting in a map

I have the following class which represents a set of properties. ...
7
votes
1answer
108 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
94 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 ...
9
votes
2answers
424 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
84 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
222 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
73 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
129 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
228 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 ...
4
votes
2answers
66 views

Data structure to store large numbers of runtime-dependent arithmetic types

Warning: lots of code. If it's too much, please focus primarly on channel.h and channel.hpp. This is my first time posting on ...
4
votes
2answers
88 views

On-line evaluation of mean and variance in C#

In various projects, I have to evaluate the mean and/or the variance of relatively large samples. I wrote the following, to help me evaluate these quantities with a constant footprint. Basically, it ...
4
votes
2answers
448 views

Generic binary tree in C#

This is a simple implementation of a generic binary tree that holds elements of type T. I was wondering if there was something that could be done better (especially in the EnumerateNodes methods). <...
3
votes
1answer
115 views

Recursive flattening of Swift sequences - an overly complicated approach

I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
6
votes
3answers
219 views

Generic graph implementation in C#

I am implementing fundamental data structures in C# while trying to learn techniques in the language to make my code cleaner, more concise, and reusable. I have implemented a generic graph with a few ...
6
votes
2answers
121 views

Implement a generic Fibonacci sequence in Rust without using Copy trait

I'm trying to learn Rust and am a beginner. How does one go about implementing a generic version of the Fibonacci sequence without using Copy trait in Rust? My code ...
6
votes
2answers
102 views

Django controller method to list the top characters, guilds, and killers

I've been reading the Chapter 8 of this book. Here's the view I'm currently coding. It list all characters/guilds according to the type of URL. ...
1
vote
0answers
54 views

.NET List Serializer design

A few weeks back I wrote a class to help serialize/deserialize objects file. The file format requested was json, then compressed. After some coding/testing I settled on this design: ...
3
votes
2answers
118 views

Avoiding misuse of optional unwrapping: LinkedList

Below is my implementation of a generic linked list in swift. Unfortunately, Swift playgrounds won't run until the compiler is totally happy - often, that involves clang making me explicitly unwrap ...
2
votes
0answers
22 views

Unification with sequence variables and flexible arity functions

Today I wrote an implementation of the unification algorithm found in Temur Kutsia's 2002 paper. I didn't just do this for fun, it's related to other research I'm doing. I'm feeling more confident in ...
1
vote
2answers
256 views

Intersect two ranges in Swift

Can you think of a reason the following extension should not be used in production, or a better way of implementing it: ...
2
votes
0answers
60 views

Generic Unrolled Linked List with IList<T> interface implementation

I was inspired by the Phillip Trelford "Beyond Lists" presentation published on InfoQ. So, I decided to make it simple, yet still capable to act as IList<T>. ...
1
vote
1answer
146 views

Simple type-safe and thread-safe Rust event system

I'm creating a relatively simple type-safe and thread-safe Rust event system. It is to be used with and within an IRC library I'm making, but should work just fine for other use-cases. It needs to be ...
5
votes
2answers
91 views

Indexed Property implementation

I have a class that encapsulates a PowerShell Runspace object which, among many other things, has methods for getting and setting variables in the session state. ...
1
vote
1answer
82 views

Using T type parameter to clone a collection

I want to clone a collection with the following method and I want to know if it can be optimized: ...
3
votes
1answer
148 views

Fixed-length Sequences in Swift 2.2

The following is an implementation of fixed-length sequences that makes very exotic (and hopefully fun) use of Swift 2.2 types. The question is what exactly is the cost of having the type checker ...
4
votes
0answers
150 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...