✅ Cannot convert from anonymous type
I have a method that takes effectively extends OrderBy, and so one of it's paramaters is a keySelector, just like in OrderBy
In my use case I separated out the intended key to make it read better, so here is it's signature
I'm then using it in this code (lambda to call
SelectByDistanceFromEnemy
just to try make the error easier to parse)
which gives me this error
cannot convert from '<anonymous type: LanguageExt.Option<Unit> unit, int index>' to '(LanguageExt.Option<Unit> unit, int index)
I don't get why it can't though. The only difference is one is an anonymous type. Anyone know why?20 Replies
I mean...
That's the difference lol
You are trying to pass in a different type as the declared type
They're the same tuple, no?
(Option<Unit>, int)
Wait that's an extension method?
just switched to my laptop
thats an extension lol, call it as an extension
an anonymous type is not a tuple no
Oh, huh.
Jayy#6249
REPL Result: Success
Result: bool
Compile: 433.751ms | Execution: 72.370ms | React with ❌ to remove this embed.
like how would these ever be the same thing?
they are totally different
Do you have to be like that about it?
im not being a dick im just trying to make you think
If you say so.
(1,2) has the type ValueTyple<int, int>
And the answer of why is because I never real deal with anonymous types and didn't notice this was actually something different.
new foo=1, bar=2 is an autogenerated compiler type
actually hmm how is that represented
Jayy#6249
REPL Result: Success
Result: RuntimeType
Compile: 381.479ms | Execution: 62.034ms | React with ❌ to remove this embed.
f__AnonymousType0#12<int, int>
and tuple is ValueTuple<int, int>
ValueTuple is also a struct
an anon type is a classAh.
So is there an easy conversion here?
there is no conversion no
this might work tho
im not actually sure if you can do extensions on tuples like that tho
hmm
Oh, that totally works.
I didn't even realise I was making them as anons and not tuples.
Which is weird because I don't seem to be doing that anywhere else in my code... oh well. Learnt something today at least. Thanks.
Jayy#6249
REPL Result: Success
Console Output
Compile: 586.269ms | Execution: 73.390ms | React with ❌ to remove this embed.
there we never actively realized you could do that, filing away for later
Closed!