typst-community / valkyrie

Type safe type safety for Typst
Other
25 stars 2 forks source link

Add schemas for argument sinks #12

Closed tingerrr closed 1 month ago

tingerrr commented 1 month ago

Many package provide argument sinks, which are frequently used to allow passing variadic positional arguments and then fail if the sink contained any named arguments.

Some of these (to be discussed which) should be provided as built in schemas with some default transformers like unwrapping only the positional arguments after the assertions ensured there are no named arguments.

JamesxX commented 1 month ago

This is one I've had a lot of trouble thinking about, which is why it hasn't yet been included. Naively, my first approach was to treat argument sinks as an amalgam of dictionary and tuple, but sometimes that tuple is actually and array, and perhaps an array of multiple different types in a particular order (e.g. alternating content and number type).

I think it might be easiest to deal with sinks is with two schemas (one for named and one for positional), treat a missing schema as a "throw an error if there's any" deal

tingerrr commented 1 month ago

I think it might be easiest to deal with sinks is with two schemas (one for named and one for positional), treat a missing schema as a "throw an error if there's any" deal

Sounds reasonable to me, could simply be z.sink(positional: schema | none, named: schema | none, ..args).

JamesxX commented 1 month ago

I like it :)