Can you take any type to a function and then cast it in X type

image
Is something along these lines possible in verse?

Hello,

I am not sure if that is possible because of the typed language restraint, but you could overload the function.

It might look like this:

    TestFunction(SomeInt:int):void=
        Print("I am an int")

    TestFunction(SomeString:string):void=
        Print("I am a string")

As long as you call the function with a compatible type, it will find the correct one to run.

There may be another way to get what your after though.

Hope that helps.

-dev

1 Like

As of today, the any type is basically a trap, I’ve never managed to make a good use of it

Maybe you can take a look at parametric classes for what you’re trying to do ? :eyes:

2 Likes

Yea, that’s one thing that crossed my mind, although passing classes seems weird to me. I can’t explicitly delete it and I guess it stays there forever at least from my experience? I fear that it will lag/crash over a period of time. Maybe you can give your thoughts on that?

What stays forever exactly?

The classes I create. If they’re being diposed automatically then I don’t know a way to confirm whether it’s actually happening. And I fear if i create too many classes then it will heavily affect performance over time

1 Like