#Best implementation of chainable function calls

3 messages · Page 1 of 1 (latest)

edgy shale
#

I am implementing a bare-bones pandas library with the following capability:

data.subset(indexes: (0,3)).agg(array.sum, fields: "quantity")

My first attempt was to make a function that stores subset, agg, etc. in a dictionary that it returns. However, typst requires additional parens around function access in dicts. So it looks rather ugly and much less readable:

#((data.subset)(indexes: (0,3)).agg)(array.sum, fields: "quantity")

My question is: does typst support a paradigm other than dictionaries to enable operator chaining?

#

A non-ideal workaround is to have a caller function that expects (name, args) pairs of things to chain:

#runner(data,
"subset",
(indexes: (0,3)),
"agg",
(using: array.sum, fields: "quantity")
"display",
()
)

But the readability isn't any better...

velvet girder
#

I think you're gonna have to wait for #1175895383600275516