Open TzviPM opened 2 days ago
💯
fluent API:
z.string().email().optional('arg')
pipe function or method:
z.pipe(v.string(), v.email(), v.optional('arg'))
current hack pipe proposal:
z |> v.string(%) |> v.email(%) |> v.optional(%, 'arg')
Fluent API still looks the most clean. But considering its downside I'd still prefer pipe function over the current hack pipe syntax proposal...
Downside of pipe function is that it will always have a limit on the number of args if you want to have good typescript support
Being able to use point free style (couple do what curried, data last functions) in a hack pipe would be ideal
z |> v.string |> v.email |> v.optional('arg')
In “ Implementation of a modular schema library in TypeScript with focus on bundle size and performance” (2003; see https://valibot.dev/thesis.pdf), Fabian Hiller presented valibot as an alternative to preexisting validation libraries that could achieve smaller bundle size by optimizing for tree shaking.
Many JavaScript apis such as RxJS, Valibot, Zod, JQuery, deal with the concept of pipelining. Existing approaches are to either:
If support for pipelining were built into the language in a way that its syntax became preferred or even increased popularity of piped apis, it would benefit the ecosystem insofar as tree shakable code leads to smaller bundle sizes and allows libraries to provide more features without requiring consumers to ship unused code.