Questions tagged [generic-function]

81 questions
0
votes
0 answers

Typing for a Python function that takes a generic class and returns a specific instance of that class

Suppose I have a class definition like this: T = TypeVar('T') class Collection(Generic[T]): ... I want to create a function like this (Data is some container type): T = TypeVar('T') def get_data(typ: Type[T]) -> T[Data]: return…
0
votes
1 answer

List function max element treating empty container in c++

How do I treat situation if the list is empty? I want the program to print "Not possible to find max on an empty list" but the value must be returned... template T max(const std::list&l){ std::list l1=l; auto…
Xavi
  • 57
  • 8
0
votes
1 answer

Std::istream& as function parameter

What is the best way to make a program that reads the elements from the input until the EOF and returns the container of read elements? This is what I have to do p.h file: #pragma once #include #include typedef double…
Xavi
  • 57
  • 8
0
votes
1 answer

Model responsibility vs Generic Function

We have MVC application written in go lang There are 2 endpoint that looks to query database to get all relevant users. /get_paginate_users - > Query Database with paginate endpoint /get_users -> [1, 2] -> Query Database with given ID. To the sake…
Ratatouille
  • 1,372
  • 5
  • 23
  • 50
0
votes
0 answers

How can I make a generic function that accepts a specific property of the returning custom interface

I want to define a generic function accepting any type or Notification object. This object has a method property. the function should accept any output that has a method property and each output has it's own method type. I need to return a type that…
rostamiani
  • 2,859
  • 7
  • 38
  • 74
0
votes
1 answer

How to have required and optional type parameters in a function and still have working type inference for recod lookup?

How to make a required type parameter Y in a function work together with another type parameter K where the latter is only used as a key in a record R = {a: 'aaa', b: 'bbb'} lookup and is not supposed to be explicitly provided? The type parameter K…
Peter Hudec
  • 2,462
  • 3
  • 22
  • 29
0
votes
2 answers

Use methods inside a generic type

Consider this class: public class A { public void method_a(){ System.out.println("THIS IS IT"); } } I want to use 'method_a' in another function using generic type to get class A. for example: public class B { public void…
Shahin Shemshian
  • 356
  • 1
  • 11
0
votes
0 answers

R: Finding the code for the data.frame method of the [ function

In R, how do I look at the code for the data.frame method of the [ function? I have tried the usual plain return on [.data.frame, [.data.frame, and [.data.frame, and none of them work, nor do any of them work with getAnywhere(). getMethod("[",…
andrewH
  • 2,281
  • 2
  • 22
  • 32
0
votes
2 answers

Can I declare just one generic function in R like 'plot or 'summary' for more than one object of the class?

Like, I have four class gevp, gpdp, and others two, and I created generic function, plot and summary for each the four classes. And I were wonder if can I create just one generic function plot and summary, for the four classes, like inside that, I…
aliocha
  • 5
  • 3
0
votes
0 answers

Error when instantiating a class which has an attribute with generic types

The following code is not completely in English but you'll get the point. class Student : public Osoba{ const int _brojIndeksa; Kolekcija _polozeniPredmeti; vector _seminarski; // naslovi seminarskih radova …
developer10
  • 1,450
  • 2
  • 15
  • 31
0
votes
2 answers

Differences between generic functions and the use of Any

I am currently learn the use of generic functions and realized the problem that they solve with some existing examples in the documentation. So instead I keep repeating functions that perform the same scheme, I can use generic functions that…
LettersBa
  • 747
  • 1
  • 8
  • 27
0
votes
2 answers

Generic functions allow different order of arguments

I defined a generic function taking 2 arguments: (defgeneric interact (a b)) The order of the arguments should not be important, so (interact x y) and (interact y x) should be the same, but I don't want to define two methods that do the same for…
cl-porky11
  • 339
  • 1
  • 11
0
votes
2 answers

How can I write a generic function in c# which will call different functions based on the type of class?

I have following generic class: public class SearchModel { public string Name { get; set; } public int? UserId { get; set; } public List result { get; set; } } public class A{ .. .. } public class B{ .. .. } and…
coder_kp
  • 1
  • 1
0
votes
2 answers

C# Populating Objects with PropertyInfo

I have the following classes: User public partial class User { public long iduser { get; set; } public string email { get; set; } public string name { get; set; } public System.DateTime birthdate { get; set; } public string about…
0
votes
1 answer

Editing default functions: Changing the default color of plot function in kernlab in R

Per the example in the kernlab documentation, plot makes a nice figure of the decision weights and boundary of an SVM model. require(kernlab) x<- rbind(matrix(rnorm(n=120,mean=-1,sd=2),,2),matrix(rnorm(120,mean=3,sd=2),,2)) y <-…
user1795995
  • 51
  • 1
  • 2