对于想了解DROPFUNCTION不知道参数的数量/类型?的读者,本文将提供新的信息,我们将详细介绍.drop函数,并且为您提供关于c#–具有引用参数/参数或匿名函数的Func/Action委托、Dr
对于想了解DROP FUNCTION 不知道参数的数量/类型?的读者,本文将提供新的信息,我们将详细介绍.drop函数,并且为您提供关于c# – 具有引用参数/参数或匿名函数的Func / Action委托、DropdownButton 错误:无法将参数类型“void Function(String)”分配给参数类型“void Function(String?)?”、function – 如何在Scala中将类型参数化参数专门化为多个不同类型?、function, new function, new Function之间的区别_javascript技巧的有价值信息。
本文目录一览:- DROP FUNCTION 不知道参数的数量/类型?(.drop函数)
- c# – 具有引用参数/参数或匿名函数的Func / Action委托
- DropdownButton 错误:无法将参数类型“void Function(String)”分配给参数类型“void Function(String?)?”
- function – 如何在Scala中将类型参数化参数专门化为多个不同类型?
- function, new function, new Function之间的区别_javascript技巧
DROP FUNCTION 不知道参数的数量/类型?(.drop函数)
我将所有函数保存在一个带有''CREATE OR REPLACE FUNCTION somefunction''
. 因此,如果我添加或更改某些功能,我只需将文件提供给 psql。
现在,如果我向现有函数添加或删除参数,它会创建一个具有相同名称的重载,并删除原始的我需要的所有参数类型按确切顺序键入,这有点乏味。
是否有某种通配符可以用来删除具有给定名称的所有函数,以便我可以在DROP FUNCTION
文件顶部添加行?
答案1
您需要编写一个函数,该函数采用函数名称,并从 中查找每个重载及其参数类型information_schema
,然后DROP
为每个重载构建并执行 a 。
编辑:结果证明这比我想象的要困难得多。看起来information_schema
它的routines
目录中没有保留必要的参数信息。所以你需要使用 PostgreSQL 的补充表pg_proc
和pg_type
:
CREATE OR REPLACE FUNCTION udf_dropfunction(functionname text) RETURNS text AS$BODY$DECLARE funcrow RECORD; numfunctions smallint := 0; numparameters int; i int; paramtext text;BEGINFOR funcrow IN SELECT proargtypes FROM pg_proc WHERE proname = functionname LOOP --for some reason array_upper is off by one for the oidvector type, hence the +1 numparameters = array_upper(funcrow.proargtypes, 1) + 1; i = 0; paramtext = ''''; LOOP IF i < numparameters THEN IF i > 0 THEN paramtext = paramtext || '', ''; END IF; paramtext = paramtext || (SELECT typname FROM pg_type WHERE oid = funcrow.proargtypes[i]); i = i + 1; ELSE EXIT; END IF; END LOOP; EXECUTE ''DROP FUNCTION '' || functionname || ''('' || paramtext || '');''; numfunctions = numfunctions + 1;END LOOP;RETURN ''Dropped '' || numfunctions || '' functions'';END;$BODY$ LANGUAGE plpgsql VOLATILE COST 100;
我在一个重载的函数上成功地测试了这个。它很快被组合在一起,但作为一个实用函数运行良好。我建议在实际使用之前进行更多测试,以防我忽略了一些东西。
c# – 具有引用参数/参数或匿名函数的Func / Action委托
这是一个例子
如果函数定义为
public void DoSomething(int withValue) { }
可以通过创建函数中的委托
public void f() { Action<int> f2 = DoSomething; f2(3); }
如果将原始函数定义为,那该语法是怎样的
public void DoSomething(ref int withValue) { withValue = 3; }
解决方法
delegate void RefAction<in T>(ref T obj); public void F() { RefAction<int> f2 = DoSomething; int x = 0; f2(ref x); }
.NET Framework不包含此类型的原因可能是因为ref参数不是很常见,如果为每个可能的组合添加一个委托类型,则所需类型的数量会爆炸.
DropdownButton 错误:无法将参数类型“void Function(String)”分配给参数类型“void Function(String?)?”
如何解决DropdownButton 错误:无法将参数类型“void Function(String)”分配给参数类型“void Function(String?)?”?
在迁移到空安全后,我开始在 DropdownButton
中看到此错误。
DropdownButton<String>(
value: myValue,onChanged: (String string) { // Error
print(string);
},items: [
DropdownMenuItem(
value: ''foo'',child: Text(''Foo''),),DropdownMenuItem(
value: ''bar'',child: Text(''Bar''),],)
错误:
无法将参数类型“void Function(String)”分配给参数类型“void Function(String?)?”。
解决方法
检查 value
属性的实现,它可以为空。
final T? value;
这意味着您可以向 String?
提供 value
,如果您提供 String?
,onChanged
应该不会返回 String?
。
回答您的问题:
将 onChanged
方法的类型从 String
更改为 String?
,如下所示:
onChanged: (String? string) {
print(string);
}
或者,只需省略 String?
类型,让 Dart 为您推断。
onChanged: (string) {
print(string);
}
function – 如何在Scala中将类型参数化参数专门化为多个不同类型?
在一篇文章(http://www.win-vector.com/blog/2010/06/automatic-differentiation-with-scala/)中我写道,我说我对Scala的信念是你不能指定一个带有参数的函数,该参数本身就是一个带有未绑定类型参数的函数.我已编辑此问题以尝试简化示例.
下面的代码通过引入模仿Scala Function1特征的特征GenericFn来工作,除了它在函数中有一个free-type参数:
object TypeExample { trait NumberBase { def result:String } class A extends NumberBase { def result = "A" } class B extends NumberBase { def result = "B" } trait GenericFn { def apply[X<:NumberBase](x:X):String } def specializeAndApplyTwice(f:GenericFn):String = { f[A](new A()) + f[B](new B()) } def main(args : Array[String]) : Unit = { val f = new GenericFn { def apply[X<:NumberBase](x:X):String = { x.result } } println(specializeAndApplyTwice(f)) } }
这有效,但有没有一种方法可以在没有GenericFn特征的情况下执行此操作(使用标准函数表示法)?例如,下面的代码失败并出现编译时错误:“type mismatch; found:TypeExample2.A required:_ $1 where type _ $1<:TypeExample2.NumberBase”:
def specializeAndApplyTwice(f:(_<:NumberBase)=>String):String = { f(new A()) + f(new B()) }
解决方法
所以我相信一种解决方案是使用通配符(一种存在抽象形式):
def g(f: Array[_ <: NumberBase[_]] => Double,z: Array[Double]): Double
关于g类型的散文解释是:从Array [T]和Array [Double]到Double的函数,其中T是扩展Double的某种类型. “some”是表示存在抽象的词,我们要求这种类型存在,尽管我们在这一点上并不关心它是哪一种.
function, new function, new Function之间的区别_javascript技巧
函数是JavaScript中很重要的一个语言元素,并且提供了一个function关键字和内置对象Function,下面是其可能的用法和它们之间的关系。
使用方法一:
var foo01 = function() //or fun01 = function()
{
var temp = 100;
this.temp = 200;
return temp + this.temp;
}
alert(typeof(foo01));
alert(foo01());
function
300 最普通的function使用方式,定一个JavaScript函数。两种写法表现出来的运行效果完全相同,唯一的却别是后一种写法有较高的初始化优先级。在大扩号内的变量作用域中,this指代foo01的所有者,即window对象。
使用方法二:
var foo02 = new function()
{
var temp = 100;
this.temp = 200;
return temp + this.temp;
}
alert(typeof(foo02));
alert(foo02.constructor());