dry-types icon indicating copy to clipboard operation
dry-types copied to clipboard

Implement Transition composition type

Open estum opened this issue 2 years ago • 2 comments

It is a composition type, where the left type is an intermediary one and the right type is a resulting.

It differs from an Implication by an input for the right type: instead of bypassing the original input, it will pass a coerced result of the left type. The same effect is possible with a Constructor but Transition allows to keep a transitive object as type instead of function.

When the left type if failed it bypasses input value to the right type.

The meta is always stored and get from the right-hand type, because the left type is not the target.

Here is a real-world example, that I use, note a combination with implication:

Callable = Types.Interface(:call)
Aref = Types.Interface(:[])
CallableAref = Callable <= (Aref > Types.Constructor(Proc, proc(&:[]).curry(2)))

CallableAref[[1,2,3]][0] # => 1
CallableAref[proc(&:nonzero?)][0] # => nil

estum avatar Feb 11 '23 15:02 estum

I like the idea but haven't looked into the implementation yet. However, I think <= is redundant. Shouldn't >= suffice?

flash-gordon avatar Feb 13 '23 07:02 flash-gordon

By the way, not to discourage you but pls submit a question about adding new features on the forum first. It would be a shame if you spend a lot of your time on something that is rejected (or requires a lot of modification) for whatever reason.

flash-gordon avatar Feb 13 '23 07:02 flash-gordon