C# CS1503 Select cannot infer type, mixed up by System.Func and Func - .net-core

I am using Select() on a collection to create many transform functions. C# is complaining the Select call cannot infer the type, apparently it is expecting a System.Func<> but is getting a Func<>...? I don't see the difference. The exact error text:
Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<Func<Foo, Foo>>' to 'System.Collections.Generic.IEnumerable<System.Func<Foo, Foo>>' [language-core]csharp(CS1503)
The code, paraphrased a bit, looks like (ExtendBy returns a Foo):
BarCollection.Select(b => ((Foo f) => f.ExtendedBy(b)))
If I specify the types related to the Select explicitly it works, but that's a hassle:
BarCollection.Select<Bar, System.Func<Foo, Foo>>(b => ((Foo f) => f.ExtendedBy(b)))
If I specify the types but use Func instead of System.Func, I get the original error as when the type is not specified:
BarCollection.Select<Bar, Func<Foo, Foo>>(b => ((Foo f) => f.ExtendedBy(b)))
So it seems like some other Func besides System.Func is getting used and confusing things. Is there a way to fix this so Select can determine the type implicitly? Both pieces of code are in the same library project, with TargetFramework set to net5.0.
For reference, here are my using statements for the file calling Select():
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

Related

How do I get output for a XQuery in MarkLogic in a one line output?

Will elaborate - when I execute the following command :
let $value := xdmp:forest-status(
xdmp:forest-open-replica(
xdmp:database-forests(xdmp:database("Documents"))))
return $value
Above query returns a lot of information about the database "Documents" forest, like - forest-id, host-id, etc.
I only require that it should return only the "state" of my forest. How do I do that?
Use XPath to select what you want to return.
let $value := xdmp:forest-status(
xdmp:forest-open-replica(
xdmp:database-forests(xdmp:database("Documents"))))
return $value/*:state/text()
Also, no need for a FLWOR you could make it a one-liner:
xdmp:forest-status(
xdmp:forest-open-replica(
xdmp:database-forests(xdmp:database("Documents"))))/*:state/text()
Or you may find that using the arrow operator makes things easier to read instead of nested function calls and tons of parenthesis wrapping them:
(xdmp:database("Documents")
=> xdmp:database-forests()
=> xdmp:forest-open-replica()
=> xdmp:forest-status()
)/*:state/text()
The XML elements in the response are in the http://marklogic.com/xdmp/status/forest namespace. So, you would either need to declare the namespace (i.e. declare namespace f = "http://marklogic.com/xdmp/status/forest";) and use the prefix in your XPath (i.e. f:state), or just use the wildcard as I have done *:state

Creating dictionary of functions with symbols as keys

I am trying to create a dictionary of functions with symbols as keys but I am getting an error. I have tried the following:
functions = Dict{
:gauss => (v::Float64)->gauss(v, 0.0, 1.0),
:sin => (v::Float64)-> sin(v),
:nsin => (v::Float64)->(-sin(v)),
:cos => (v::Float64)-> cos(v),
:ncos => (v::Float64)->(-cos(v)),
:tanh => (v::Float64)->tanh(v),
:sigm => (v::Float64)->sigmoid(v),
:id => (v::Float64)->id(v)
}
The error I am getting :
ERROR: LoadError: TypeError: in Type, in parameter, expected Type, got Pair{Symbol,getfield(Main, Symbol("##105#113"))}
Please let me know what I am doing wrong. Thanks for the help in advance.
I figured the{} need to replaced by ().
As you found out your yourself, the {} brackets indicate type parameters whereas the paranthesis indicate a constructor call.
Note, that the ::Float64 type annotations aren't necessary for your functions to be performant. Think of them more as a user interface restriction; that is users won't be able to call your methods with non-Float64s. However, if you want to specify types explicitly, you could also specify the type of your dictionary explicitly as such Dict{Symbol, Function}(...). However, since you don't initialize the Dict empty, Julia will figure out the best type based on your input (symbol function pairs).

Is there some way to specify a "not" type in flow?

Is there some way to specify a "not" type in flow? For example,
compact = (input: Array<any>): Array<notFalsey> => input.filter(i => !!i);?
Currently, there is no syntax to specify a "not" type, like $Not<string>, which would be anything but a string.
For your specific compact example, Flow's library definition for Array.prototype.filter does include a special case for using the Boolean function as the filter function. So you can write
const compactedArray = myArray.filter(Boolean);
v0.31.0 will ship with a magic type $NonMaybeType, so you will be able to write a compact function with return type Array<$NonMaybeType<T>>.

Oracle named parameters

How can I use keywords with Oracle named parameters syntax ? The following gives me 'ORA-00936: missing expression' because of the 'number'-argument:
select b.g3e_fid
, a.g3e_fid
, sdo_nn_distance( 1)
from acn a, b$gc_fitface_s b
where mdsys.sdo_nn ( geometry1 => a.g3e_geometry, geometry2 => b.g3e_geometry, param => 'sdo_num_res=1', number=>1) = 'TRUE' and b.g3e_fid = 57798799;
If I run it without named parameters it is fine.
thanks, Steef
Although you can get around the reserved word issue in your call by enclosing the name in double quotes as #AvrajitRoy suggested, i.e. ... "NUMBER"=>1) = 'TRUE'..., you aren't actually achieving much. Oracle is letting you refer to the parameters by name but it isn't doing anything with that information.
MDSYS.SDO_NN is a spatial operator, not a direct call to a function. There is a function backing it up - you can see from the schema scripts for MDSYS that it's actually calling prtv_idx.nn - but the names of the formal parameters of that function are not relevant. With some digging you can see those are actually called geom, geom2, mask etc., and there isn't one called number (and you can't have a formal parameter called number, even quoting it, as far as I can tell).
The formal parameters to the operator are not named, and are effectively passed through positionally. You can't skip an argument by naming the others, as you can with a function/procedure with arguments that have default values.
So that means you can call the parameters anything you want in your call; changing the names of the first three parameters in your call to something random won't stop it working.
It also means naming them in the call is a bit pointless, but if you're just trying to document the call then you can use some other meaningful name rather than 'number' if you don't want to quote it.
Hello as mentined in you question . There are two ways in which u can eliminate this RESERVED keyword ISSUE.
1) Use "" to use any RESERVED key word for calling. But remember this is not a good coding practice.
Eg >
SELECT b.g3e_fid ,
a.g3e_fid ,
sdo_nn_distance( 1)
FROM acn a,
b$gc_fitface_s b
WHERE mdsys.sdo_nn
( geometry1 => a.g3e_geometry,
geometry2 => b.g3e_geometry,
"param" => 'sdo_num_res=1',
"NUMBER"=>1) = 'TRUE'
AND b.g3e_fid = 57798799;
2) Secondly you can just call the function without using "=>" as shown below
Eg >
SELECT b.g3e_fid ,
a.g3e_fid ,
sdo_nn_distance( 1)
FROM acn a,
b$gc_fitface_s b
WHERE mdsys.sdo_nn
( a.g3e_geometry,
b.g3e_geometry,
'sdo_num_res=1',
1) = 'TRUE'
AND b.g3e_fid = 57798799;

How to implement generic Max<TSource>(Func<TSource,TSource> func)

I am busy writing my own collection type and need to have a function
Max that returns the value in the collection, where one of the value attributes is a max or some condition holds.
So I am trying to call Max(Func<...) on one of the underlying .net collections, but
I can't seem to get it to work:
public TValue MaxValue(Func<TValue,TValue> func)
{
return this.valueSet.Max<TValue>(func);
}
but I am getting 2 errors:
Argument 2: cannot convert from 'System.Func<TValue,TValue>' to System.Func<TValue,int>'
and
'System.Collections.Generic.SortedSet<TValue>' does not contain a definition for 'Max'
and the best extension method overload 'System.Linq.Enumerable.Max<TSource>(System.Collections.Generic.IEnumerable<TSource>,
System.Func<TSource,int>)' has some invalid arguments
I just can't seem to figure out what I should be doing here...
When you call:
this.valueSet.Max<TValue>(func);
the compiler interprets this as one of the Max overloads with one generic type. Either explicitly point out that the return value also should be a TValue type:
this.valueSet.Max<TValue, TValue>(func);
or use implicit typing and let the compiler sort out the types itself:
this.valueSet.Max(func);

Resources