|
04:10
Flwyd joined
|
|||
| Flwyd | Is there a syntax for getting a method reference as a callable? In the same way that $x.map(&foo) passes subroutine foo to map, I'd like to pass a bound method, e.g. $x.map(&$y.bar). | 05:14 | |
| (The only thing I've found which works is invoking the method in a block: $x.map({ $y.bar($^a) }). This works, but it seems like Raku would have a way to treat a method as a first-class object. | 05:16 | ||
| CIAvash | Flwyd: you can do it with `^find_method`. `Y.^find_method('bar')`. And if `$x` doesn't contain objects of type `Y`, then you need to pass the object to the method: `Y.^find_method('bar').assuming: $y`. I don't think there is any other way, because the first parameter of a method is the invocant. | 06:19 | |
| Flwyd | Interesting, thanks. `<foo bar baz>.map: Str.^find_method('uc')` for a concrete example. | 06:26 | |
|
06:50
mjgardner left
06:53
mjgardner joined
|
|||
| Nemokosch | btw uc exists as a sub as well | 10:06 | |
| So you wouldn't have to do this in this concrete case | |||
|
13:39
A26F64 joined
13:44
sm2 joined
|
|||
| CIAvash | If they wanted to just call a method, then they could just write `<foo bar baz>.map: *.method_name`. Their original question suggested something else. | 13:53 | |
|
14:32
sm2 left
14:56
sm2 joined
15:03
sm2 left
15:24
sm2 joined
16:43
sm2 left
17:12
sm2 joined
18:54
sm2 left
19:25
sm2 joined
19:39
sm2 left
21:53
A26F64 left
22:27
sm2 joined
22:52
sm2 left
23:09
sm2 joined
23:18
sm2 left
|
|||