kdb - 验证输入参数的功能
问题描述
定义了验证输入参数的方法:
`validate_paramaters{[Date;Code;CodeType;Param]
if[ not (14h=abs[type[Date]]);
[
.log.info["\tError - Exiting function - Date is not of the correct type"];
: `$"Error - Date is not of the correct type"
]
];
if[ not (11h=abs[type[Code]]);
[
.log.info["\tError - Exiting function - Code is not of the correct type"];
: `$"Error - Code is not of the correct type"
]
];
if[ not (-11h=type[CodeType]);
[
.log.info["\tError - Exiting function - CodeType is not of the correct type"];
: $"Error - CodeType is not of the correct type"
]
];
:`validated
}`
但是现在 CodeType 的类型增加了更多:
-11h=type[CodeType] `also can be` 99h=type[CodeType]
请给我一个指导,我现在如何验证 CodeType
解决方案
替换你not (-11h=type[CodeType])
的not any -11 99h in type CodeType
关键字in
允许您将 CodeType 的类型与数字类型列表进行比较。这将返回一个布尔列表。例如:
q)CodeType:`sample`dictionary!`a`b
q)-11 99h in type CodeType
01b
如果列表的任何成员为 True,则any
前面的返回 a 。1b
q)any -11 99h in type CodeType
1b
最后,如果 CodeType 不是上述类型之一,您似乎会抛出错误,因此我们将在这一切前面加上not
.
推荐阅读
- ios - 如果索引超出范围,则提供捕获(Swift 5)
- java - 在 ConstraintLayout 中使用打包链样式时如何防止出现双边框
- python - Python - 使用字典和元组查找单词和字母的唯一计数
- swift - 使用 NotificationCenter 从另一个视图控制器调用时表视图不更新
- javascript - 简单的 JS vanilla/react 函数重写,但是如何重写?
- reactjs - 如何通过从 axios 获取使用反应功能组件的 useState 中的数据
- python - 如何在 Flask SQLAlchemy 中使用 SUM 聚合函数?
- django - Django Rest Framework 使用相同的序列化程序以两种不同的方式序列化对象
- equals - 使用等于运算符将输出什么代码
- flutter - 如何在 AutoCompleteTextField Flutter 中将文本居中