Open ioquatix opened 4 years ago
This could work, namely, it would be extremely easy to build something up using refinements + the Ruby syntax of:
type { [Array[String, Symbol]] => String }
def foo(arr) end
That said, have you taken a look at Sorbet? The syntax is a little less familiar, but provides much of the same logic you're probably looking for, plus it has a full type checking runtime.
Yeah, it makes sense. I prefer something similar to YARD syntax, because I want to use the type signature for parsing string arguments into rich data.
I'm going to hopefully put this code in it's own gem, but here is a proof of concept I whipped up:
https://github.com/ioquatix/bake/blob/master/lib/bake/types.rb#L34
Parsed by files in:
https://github.com/ioquatix/bake/tree/master/lib/bake/types
It's a little bit less terse than the syntax of this repository, but it's very simple and logical to parse which is good for my usecase.
I'd like to be able to use Ruby to parse types.
This might not be practical, but it would be nice if I could define my types as classes, and then use
eval
on a string to build a type tree.For example:
Do you think something like this makes sense?