-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter folding for element field unions #10
Comments
It is notably supported for However, I haven't implemented it (at least yet) for arbitrary unions because it can be ambiguous. Consider that you have a type A that wraps int, type B that also does so, and type C that wraps stroke. You can't know which folder to use even if A and B have different checks, since they may cast to something that doesn't satisfy the checks, and the fold would still have to work. With that said, we can probably add an automatic implemention when the type's list of possible outputs have no intersection, in which case we can fold if you set two things of the same type, otherwise we don't. It is worth noting, though, that you can use |
With that said, we should definitely at least implement it for (But note that it wouldn't be implemented for |
That would make me very happy ^^ Call it |
This sounds good. How would you do that (in a minimal example)? |
Haha, it probably won't need a dedicated name and will be automatically detected :)
You should be able to get away with something like e.types.wrap(
smart(option(stroke)),
fold: old-fold => (outer, inner) => if inner in (none, auto) or outer in (none, auto) { inner } else { (e.types.native.stroke_.fold)(outer, inner) }
) Note that In addition, |
Works like a charm! Thank you :) |
Fwiw, regarding my original reply, I thought about it further and I think we can use the fact that unions are ordered to our advantage. We can have it work as follows: at fold time, we verify the type of the value being folded, and use the fold function from the first type with a matching output type. At least, this could be a good default and ensures we won't arbitrarily discard fold functions of things. |
For elements, folding is currently only support for single built-in types, like
stroke
. I'd love to somehow have folding work withe.union(stroke, none)
ore.union(stroke, none, auto)
, probably with a custom folder.In the standard library, this application can for example be found in
rect.stroke
The text was updated successfully, but these errors were encountered: