基于modules的dolphindb 函数链式调用的实现方式

本人正在写一个模块。

以下场景主要在于modules模块中实现。


本人想实现dolphindb已有的链式调用方式。 比如

database(::getDatabase()).createPartitionedTable(mtable,name,"trade_date")

而非必须变成

createPartitionedTable(database(::getDatabase()),mtable,name,"trade_date")


主要图的是简单和美观


-------------------------------------

我目前的想法是 
use log

config = init("日志名称","任务类别")

config.info(message)
config.error(message)

否则的话,我只能在每个info里放入config
请先 登录 后评论

2 个回答

Polly

经过沟通 了解了您的具体需求是,将多个参数传参后,一起采用链式调用,对于自定义函数,可以通过元组的形式传参,如:

def info(config){
print(config[0])
print(config[1])
}
config1=("日志", "任务类别")
config1.info()


请先 登录 后评论
peter
def info(logger, message){
   print(message)
   //logger.append!() //实现下日志的sync方式,可以写入dfs表
}

def error(logger, message){
   print(message)
   //logger.append!() 
}

logger = writeLog // 指定具体的实现

info(logger, "hello world!")// ok

logger.info("hello world!") //可读性更高
logger.error("bug here...")
请先 登录 后评论
  • 2 关注
  • 0 收藏,601 浏览
  • 柏木 提出于 2023-07-09 20:24