Questions tagged [return-type]

This tag is for questions dealing with the type of the variable or value returned by a function.

Filter by
Sorted by
Tagged with
0 votes
0 answers
7 views

Why does this Kotlin function definition have an extra empty set of parentheses before the return type?

I'm going through one of Google's Kotlin codelabs. I'm in Kotlin fundamentals under Android basics with Compose > Building app UI > Kotlin fundamentals, and I'm on section 5, "Use function ...
savedR's user avatar
  • 1
0 votes
1 answer
72 views

Trying to deep merge on type level

I have a JavaScript mergeDeep function that recursively merges objects and arrays. It works as expected in terms of functionality, but I want to improve it by ensuring that the return type of the ...
stambolievv's user avatar
0 votes
0 answers
39 views

Return type of Function with Parameters

def add(num1:int,num2:int ) -> str: num3 = num1+num2 return num3 num1 , num2 = 5,6 ans = add(num1,num2) print(type(ans)) print(f"Addition of {num1} and {num2} is {ans}") I was ...
Y Chandra Sekhar Reddy's user avatar
0 votes
1 answer
44 views

RETURN cannot have a parameter in function returning set while returning from function

I have following code but this is throwing error: RETURN cannot have a parameter in function returning set Any idea on how I can fix it and why I am getting this error? DROP FUNCTION IF EXISTS ...
Alwaysblue's user avatar
  • 10.1k
-1 votes
3 answers
113 views

Is it OK to return a struct in a C function, or is it better to return a pointer to a struct created with malloc() [closed]

Both options are legal, but which one is better or "cleaner" : Suppose we have this structure: typedef struct MyStruct { int val; } MyStruct; 1st option; returning directly a struct: ...
Wheatley's user avatar
  • 162
0 votes
1 answer
23 views

How can I return different values in a FormComponent method?

I have this method that is going to create 2 textfields and a combobox. But I have a problem returning the different values because it gives me an error that "Type mismatch: cannot convert from ...
Diogo Cruz's user avatar
-2 votes
2 answers
45 views

Text Box functions have wrong return type in Windows forms app [closed]

I've recently started learning .NET development. I was trying to make a basic SQL server connect form and I keep running into a wrong return type error for the Text Box functions that accept the ...
Random dude's user avatar
0 votes
0 answers
29 views

What is the proper way to override a method's return type in TypeScript?

In the Point2D class below, I got the compiler to stop complaining about the following error: Property 'clone' in type 'Vector2D' is not assignable to the same property in base type 'Point2D'. By ...
Mr. Polywhirl's user avatar
2 votes
1 answer
80 views

Why is there an error when the return type is std::string in C++?

I have an enum class and a map which matches enum class values to strings. For example, enum class FRUIT { APPLE, ORANGE, MELON }; std::map<FRUIT, std::string> m { {FRUIT::APPLE,...
MinLinC's user avatar
  • 47
0 votes
0 answers
32 views

c++.net Winform function cannot be destinguished even though it has a unique name

I am writing a simulation with a winform user interface in C++. To pass information to the user interface, I intend to use a structure that is passed as a function. I have multiple files that are all ...
Kvaestr's user avatar
  • 77
1 vote
1 answer
28 views

Typescript: getting ReturnType of a function called with certains Parameter types

Functionally, I want to provide 2 interface to access my database: dao may be used by admins or regular users, so we need to provide isAdmin:boolean as first param of each function (eg: updateUser(...
TOPKAT's user avatar
  • 6,784
2 votes
2 answers
98 views

What is the difference of using `typename` in the following?

What is the difference between using "typename" before the return type of a function and without using it at the declaration of a function like the following below? And what is different if ...
Crackie's user avatar
  • 209
0 votes
2 answers
30 views

Data type of Function with void return type and taking no input parameters

I am unable to figure what would be the return type of these functions fooBar() and barFoo() in Java and getting the following errors. import java.util.function.Function; class FooBar { private ...
Mradul Singhal's user avatar
0 votes
1 answer
27 views

PHP - Spoofing return-type covariance for code prediction

Consider: abstract class BaseModel { protected static string $dataObjectClass; public function toDataObject(): ?IDataObject { return static::$dataObjectClass::from($this); } } ...
Rikaelus's user avatar
  • 584
0 votes
0 answers
28 views

(Used PyCharm, Python, OpenCV, Mediapipe) When using Mediapipe what does process() function return?

Here is the code. import cv2 import mediapipe as mp webcam=cv2.VideoCapture(0) mp_face=mp.solutions.face_mesh mp_drawing=mp.solutions.drawing_utils with mp_face.FaceMesh(min_detection_confidence=0.5,...
SamuelWhiskeyJohnson's user avatar
0 votes
0 answers
9 views

Return an objet or id from post request

Does a post request have to return a DTO like that: return CreatedAtAction(nameof(GetUser), new { id = _user.Id }, _user); or only the id return CreatedAtAction(nameof(GetUser), new { id = _user.Id },...
Manta's user avatar
  • 490
1 vote
1 answer
87 views

How does return work within a Monad context within Haskell

Why does the following, given that the RegModule instance defines its return as: return a = RegModule (\_s _i d -> return (a, 0, d)), not return [((c, i+1, d), Int, d)], and why does the second ...
Piskator's user avatar
  • 605
4 votes
1 answer
162 views

Marking the return value of a property in a method signature as readonly in C#

Visual studio is recommending I add the readonly keyword to the return signature of some methods and properties (IDE 0251). IDE 0251 has no title or description, which looks like it has been reported ...
Brett Woodard's user avatar
1 vote
2 answers
100 views

How to get return type of class method?

I tried to use std::result_of, but could not manage it. #include <type_traits> class Foo { public: int foo(); }; int main() { using return_type = std::result_of_t<Foo::foo()>; //...
mouse_00's user avatar
  • 593
0 votes
0 answers
14 views

Cannot Convert value of type "CLLocationCoordinates2D" to closure result type 'Void' [duplicate]

In this swift code, I am trying to make the function convert an address to a string, and after it does so successfully, it should return the coordinate as a CLLocationCoordinate2D The error, Cannot ...
CoolCrafts Bayarea's user avatar
1 vote
1 answer
84 views

Collecting return types from vararg Callable for use elsewhere in signature?

I have the following function signature: Y = Annotated[TypeVar("Y"), "That which might be yielded"] R = Annotated[TypeVar("R"), "That which might be returned"] ...
JamesTheAwesomeDude's user avatar
1 vote
1 answer
38 views

Typescript return type of intersected functions is mismatched with the inferred type

As I was trying to extract the return type of a request that is intersected, I came across the this mismatch of the return type and the inferred type. Here is the shortened url https://tsplay.dev/...
Kostas Xafis's user avatar
1 vote
1 answer
54 views

Kotlin return type inference based on multiple parameter types

As a followup to Kotlin return type inference based on parameter type and incorporating its answer, here is my next question. Consider the following code: enum class Usage { REQUIRED, OPTIONAL,...
Rik Schaaf's user avatar
  • 1,101
1 vote
3 answers
92 views

Kotlin return type inference based on parameter type

I have a function: object CliUtils { var skipOptionalArgs = false fun readOptional(variableName: String, defaultValue: String? = null): String? { if (skipOptionalArgs) return ...
Rik Schaaf's user avatar
  • 1,101
1 vote
1 answer
46 views

Incompatible pointer types returning swift class from Obj-C function

I have a swift protocol Fruit, a swift class Pear, and a method in an Objc-c file returning a pointer to Pear. protocol Fruit: NSObjectProtocol { } @objcMembers class Pear: NSObject, Fruit { init() ...
Brinkster's user avatar
  • 194
1 vote
1 answer
52 views

Why does Kotlin resolve return type inconsistently?

Given the following code: inline fun <reified T> T?.or(other: () -> T): T { return this ?: other() } fun getValue(): String { while (true) { return "Value 1" } }...
Rik Schaaf's user avatar
  • 1,101
1 vote
3 answers
96 views

Can I use the return type "object" in Java? Dangers?

During a project the need for a queue supporting two different datatypes arose. I solved this by creating a java.util linked list using java.util queue interface. I do however need to use the return ...
Boosen's user avatar
  • 19
0 votes
3 answers
54 views

Confusion on inferred return type

I was working with Typescript and got confused with how the compiler infers the return types differently for these two functions. //this is of type () => boolean | "" const isFormValid = (...
snippetkid's user avatar
2 votes
1 answer
78 views

differentiate and nest function with template return type

What I want: I have an issue with using 'nested'(?) templates as return type for my functions. The function declaration should look something like this: // ### Generate.hpp // return the template type ...
melon_maniac's user avatar
0 votes
1 answer
42 views

C# methodology advices in DLL dev, and custom result classes

I would need some advice on development methodology in a C# DLL with a GUI, especially on the return objects of the methods which must return both processing results and possible exceptions or errors, ...
jeheel's user avatar
  • 11
-1 votes
1 answer
67 views

Difference between 'void' and ' <T> void' in java method [closed]

public static <T> void myMethod(int a, Consumer<T> consumer){// Some code} public static void myMethod(int a, Consumer<T> consumer){// Some code} Difference between 'void' and '<...
Sahil Parekh's user avatar
1 vote
0 answers
37 views

Return Type of a Function?

I am trying to write an AI in unity for a simple 2D game I have made, I am trying to use the code from a simple genetic algorithm tutorial on unity but I don't what type of return unity wants me to ...
Paken Playz's user avatar
0 votes
0 answers
17 views

Dummy return value for Generic Method [duplicate]

I'm writing a few empty generic methods that I plan on coming back to finish later. However, I still want the program to compile. How do I return an empty generic method? For example: public AnyType ...
idkusrname126's user avatar
0 votes
0 answers
33 views

lambda return type restriction for C++11 [duplicate]

So i am working on a C++11 project and i have class structure something like this header file class AgentClassInterface { public: virtual void doSomething() = 0; }; class AgentClass : public ...
bourne's user avatar
  • 1,101
0 votes
0 answers
54 views

Generic type with suggested functions in any property interface in Typescript

This is a followup to this question and this question. // return type interface DataA { value: number; } // return type interface DataB { text: string; } // return type interface DataC { has: ...
Kleywalker's user avatar
-3 votes
2 answers
51 views

Void function with an Error of non-void function does not return a value [closed]

Could anyone help me understand why this function produces an error of: error: non-void function does not return a value [-Werror,-Wreturn-type] } ^ 1 error generated. void *ft_clearpath(char **arr) {...
jdagz's user avatar
  • 43
0 votes
1 answer
52 views

Expect functions and suggest function names in generic class

Hi everyone. 😊 This is a followup to this question. interface Works { call(): void; } interface DoesntWork { value: number; } interface ShouldWork { value: number; call(): void; } class ...
Kleywalker's user avatar
0 votes
0 answers
12 views

Return something from Closure

def create_counter(): count = 0 def counter_inner(): nonlocal count count += 1 print(f'Closure called {count} times') return counter_inner c1 = create_counter() c2 ...
Qaiser Muhammad's user avatar
3 votes
0 answers
112 views

Specifying of full namespace in function return type

I have the following code. Header file myclass.h: namespace A::B { template<typename Type, unsigned int Count> class MyClass { public: MyClass() = delete; ...
Eugene's user avatar
  • 87
1 vote
1 answer
138 views

Depending Generic ResultType in Typescript

😊 Hi everyone! interface Data { date: Date; message?: string; } interface DataB { dateB: Date; messageB?: string; } class DataResolver { public submit(): Data { return { date: new ...
Kleywalker's user avatar
0 votes
2 answers
86 views

How to deduce return type of each function (on derived class) stored in a container

I would like to get return type of each function stored in a container. I have tried std::any and std::variant but i couldn't figure this out. Details below: #include <random> #include <...
Kitiara's user avatar
  • 341
0 votes
1 answer
43 views

How can I make a java method return an object found in a list of objects? [duplicate]

I have this code: public Task getTask(String taskID) { for (Task item : tasks) { if (item.getTaskID() == taskID) { return item; } } ...
Fooze666's user avatar
0 votes
2 answers
70 views

Python - possible problem returning a value in a function which can rerun itself

# Python code to check input for "" and diving by zero error def getNumber(): x = input("Enter a number to divide 100 by: ") # string!! if x == "&...
Micklos's user avatar
  • 109
2 votes
1 answer
57 views

Purpose of return expression in c

#include<stdio.h> long int multiplyNumbers(int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d",&n); printf("Factorial of ...
Uuuuuuu's user avatar
  • 31
-1 votes
2 answers
62 views

Need to only return what's in the if-statement, but get an error with only one return statement

For my program, I'm trying to just return the value of index, which is equal to i. Except Java won't let me return just that if-statement without an error message. I added a return index statement at ...
Mauimeow23's user avatar
-1 votes
1 answer
51 views

What can I use instead of 'None' so it'll be iterable? [closed]

Is there something I can return instead of 'None' so that it's still iterable but empty? Sometimes I want to return two values but sometimes I only want to return one. for distance in range(1, 8): ...
ThePawn08's user avatar
1 vote
0 answers
31 views

Complex unions as return type annotations in Python?

I'm writing a basic python function that takes user input, checks if it's valid, and returns True if the input is valid and False accompanied by an error message of type str if not. Here's what my ...
Dylan Cancelliere's user avatar
1 vote
2 answers
251 views

Template function deducing return type

I am trying to create a simple template function which takes a callable object and a couple of int values as parameters to that callable, and returns the result of invoking the callable with those ...
WalderFrey's user avatar
2 votes
1 answer
92 views

How to return a generic struct in Rust

Beginner in Rust, I'm wondering how to return generic data in a function. pub fn tryparse() -> (CLIAction, ArgSingle) { let args = CLI::from_args(); match args.cmd { SubCommand::Add(...
lvictorino's user avatar
0 votes
0 answers
84 views

TS can't infer return type of simple function

I feel like I've done this a thousands times and it should work. Why doesn't it? I am sending string so TS should know a string will come back out, right? export function sayHi(text: string | null) { ...
Ivo Ivanov's user avatar

1
2 3 4 5
31