[17:41] Hi! I think there should be a more direct and concise way to do following check: `[and] ['dfd', 1, 2, NaN, 32, Whatever].map({ $_ ~~ Numeric or $_ ~~ NaN })` . I want to verify that the elements of an array are one of two possible classes/objects. I tried coming up with an `.all` statement without much success. E.g. `[1, 2, 32, NaN] ~~ (Numeric | NaN)`.
[17:41] Hi! I think there should be a more direct and concise way to do the following check: `[and] ['dfd', 1, 2, NaN, 32, Whatever].map({ $_ ~~ Numeric or $_ ~~ NaN })` . I want to verify that the elements of an array are one of two possible classes/objects. I tried coming up with an `.all` statement without much success. E.g. `[1, 2, 32, NaN] ~~ (Numeric | NaN)`.
[17:41] Hi! I think there should be a more direct and concise way to do the following check: `[and] ['dfd', 1, 2, NaN, 32].map({ $_ ~~ Numeric or $_ ~~ NaN })` . I want to verify that the elements of an array are one of two possible classes/objects. I tried coming up with an `.all` statement without much success. E.g. `[1, 2, 32, NaN] ~~ (Numeric | NaN)`.
[17:55] ```perl
[17:55] > [1,2,32,NaN].all ~~ (Numeric | NaN)
[17:55] True
[17:55] > [1,'s',32,NaN].all ~~ (Numeric | NaN)
[17:55] False
[17:55] > [].all ~~ (Numeric | NaN)
[17:55] True
[17:55] ```
[18:07] Hi! I think there should be a more direct and concise way to do the following check: `[and] ['dfd', 1, 2, NaN, 32].map({ $_ ~~ Numeric or $_ ~~ NaN })` . I want to verify that the elements of an array are one of two possible classes/objects. I tried coming up with an `.all` statement without much success. E.g. `[1, 2, 32, NaN].all ~~ (Numeric | NaN)`.
[18:11] @Bearhug#1761 No, that does not work -- I tried that. (I pasted incorrect code in my question above, it is corrected now.) To see that it does not work try this: `['dfd', 1, 2, 32, NaN].all ~~ (Str | Numeric | NaN)` .
[18:12] @Bearhug#1761 No, that does not work -- I tried that. (I pasted incorrect code in my question above, it is corrected now.) To see that it does not work try this: `['dfd', 1, 2, 32, NaN].all ~~ (Str | Numeric | NaN)` . (Gives `False`.)
[18:52] m: say NaN.WHAT;
[18:53] @Anton Antonov#7232 NaN is not a typeobject. You have to use `.isNaN` .
[18:55] m:```
[18:55] subset StrNumeric where * ~~ Str | Numeric;
[18:55] say ('dfd', 1, 2, NaN, 32).all ~~ StrNumeric;
[18:55] ```
[18:55] Any fancy type check is best placed inside a subset.
[18:58] `['dfd', 1, 2, 32, NaN].all ~~ (Str | Numeric | NaN)` doesn't work because it expands to `(.all ~~ Str) | (.all ~~ Numeric) | (.all ~~ NaN)`
[19:00] @Morfent#9811 Thanks, that clarifies it.