| Anton Antonov | 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)`. | |||
| 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)`. | |||
| Bearhug | ```perl | 17:55 | |
| > [1,2,32,NaN].all ~~ (Numeric | NaN) | |||
| True | |||
| > [1,'s',32,NaN].all ~~ (Numeric | NaN) | |||
| False | |||
| > [].all ~~ (Numeric | NaN) | |||
| True | |||
| ``` | |||
| Anton Antonov | 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:07 | |
| @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: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)` . (Gives `False`.) | 18:12 | ||
| gfldex | m: say NaN.WHAT; | 18:52 | |
| @Anton Antonov#7232 NaN is not a typeobject. You have to use `.isNaN` . | 18:53 | ||
| m:``` | 18:55 | ||
| subset StrNumeric where * ~~ Str | Numeric; | |||
| say ('dfd', 1, 2, NaN, 32).all ~~ StrNumeric; | |||
| ``` | |||
| Any fancy type check is best placed inside a subset. | |||
| Morfent | `['dfd', 1, 2, 32, NaN].all ~~ (Str | Numeric | NaN)` doesn't work because it expands to `(.all ~~ Str) | (.all ~~ Numeric) | (.all ~~ NaN)` | 18:58 | |
| Anton Antonov | @Morfent#9811 Thanks, that clarifies it. | 19:00 |