Questions tagged [generic-function]

81 questions
1
vote
0 answers

Methods selection for an inherited S4 class

My question is how to apply the generic function plot() using my new method for my inherited S4 class. I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class, and define a new method for generic function plot for the…
Camford Oxbridge
  • 834
  • 8
  • 21
1
vote
1 answer

Avoid having to specify T type in a generic function

I've got this generic extending function that cast an object with a specific parent type as a child type (found the code here : Unable to Cast from Parent Class to Child Class) : public static U ParentToChild(this T parent) { …
1
vote
3 answers

avoid repeating code in swift 4

I would like to create a generic function to avoid repeating while using conditions. Is there any possible ideas to achieve this? Thanks struct ObjectDataItem { var name: String var value: String } static func arrayFields(arrayObject: ArrayObject)…
dicle
  • 1,122
  • 1
  • 12
  • 40
1
vote
1 answer

R: Creating S3 object with separate internal and external names

I am trying to figure out how to create a class in R with certain properties. Basically I'd have a constructor that takes a data frame as it's first argument followed by mandatory identification of certain columns or column ranges, by name(s) or…
andrewH
  • 2,281
  • 2
  • 22
  • 32
1
vote
0 answers

Override non-default method and avoid recursion

What programming principles can help me avoid recursion when using the generic function system to dispatch a modified method that calls the original method? Background I'm not satisfied with the behavior of bit64::as.integer64.character() for…
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
1
vote
2 answers

Call generic closure with concrete type

Is it possible to call a generic function using a concrete type, with a concrete struct? Here a small example of what I want to do: trait T {} trait T2 {} struct S1 {} struct S2 {} impl T for S1 {} impl T for S2 {} fn test(foo: &S1, bar: &S2,…
Cooki3Tube
  • 107
  • 1
  • 10
1
vote
1 answer

Core Data / Swift 3.0

Here is a function (very useful to insert information into Core Data) that has been working for quite a long time. Since I moved to Swift 3.0, it is having trouble, crashing on the first line. Did I miss something? func…
Michel
  • 10,303
  • 17
  • 82
  • 179
1
vote
2 answers

Conform class extension to generic protocol function

* Short version * How can I conform a class (extension) to a generic protocol function? * Long version * This is a small part of a data structure to support a paginated collection, protocol Pageable { //an object whose can be in a…
jalone
  • 1,953
  • 4
  • 27
  • 46
1
vote
3 answers

problem writing a simple STL generic function

I'm self-learning how to create generic functions using iterators. As the Hello World step, I wrote a function to take the mean in the given range and returns the value: // It is the iterator to access the data, T is the type of the data. template…
recipriversexclusion
  • 13,448
  • 6
  • 34
  • 45
1
vote
0 answers

Comment of generic function (C++/CLI) not recognized in C# and Visual Studios' Object Browser

I recognized two issues in commenting (XML style) Visual C++/CLI generic functions. Typed functions behave as expected. System configuration is Windows 7 and Visual Studio Premium 2013. The project is a C++/CLI project and outputs a…
Christian St.
  • 1,751
  • 2
  • 22
  • 41
1
vote
1 answer

trait constraint on specific function rather than whole implementation

I'm trying to implement a generic struct that can take any type parameter. struct Position{ x: T, y: T, } impl Position{ fn add(&self, other: &Position) -> Box>{ box Position{x:self.x + other.x,…
basic_bgnr
  • 697
  • 5
  • 14
1
vote
1 answer

Common lisp CLOS dispatch

Is there a good way to get a generic function to dispatch on the car of a list? I've been working on a symbolic algebra program, and at the moment am storing a lot of data as lists with different keywords as the cars to indicate type. For example,…
Riley
  • 982
  • 1
  • 7
  • 19
1
vote
2 answers

Common Lisp: Generic Function Specializing on Array Length

I am just getting started with generic functions and am wondering if this is possible (I really hope so!). I have made 3 packages for handling vectors of different lengths: vector2, vector3 and vector4. Each package has functions that handle vectors…
Baggers
  • 3,183
  • 20
  • 31
0
votes
0 answers

How to make a version of LINQ OrderBy, which uses a Radix Sort for Dates

This specification requires the algorithm to have the lowest possible order of complexity. I am trying to create my own version of LINQ .OrderBy() to achieve this, using a Radix Sort. IE I am trying to create var sortedListOfAppointments =…
delphie
  • 1
  • 1
0
votes
1 answer

How to pass different `rapidjson::GenericObject`s to function?

I have a function where I would like to pass a rapidjson::GenericObject as a parameter, e.g. MyObject readObject(rapidjson::GenericObject& obj) { // ... } However, depending on how I extract the object,…
Markstar
  • 639
  • 9
  • 24