typst-community / valkyrie

Type safe type safety for Typst
Other
33 stars 4 forks source link

Add schemas for argument sinks #12

Closed tingerrr closed 5 months ago

tingerrr commented 6 months 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.

jamesrswift commented 6 months 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 6 months 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).

jamesrswift commented 6 months ago

I like it :)