From type/Any
See primary documentation in context for routine snitch
multi sub snitch(\snitchee)multi sub snitch(, \snitchee)method snitch(\snitchee: = )
Available as of 6.e language version (early implementation exists in Rakudo compiler 2022.12+).
The snitch
method / subroutine is a debugging / logging tool that will always return any invocant / argument given unchanged.
By default, it will note the invocant / argument, but this can be overridden by specifying a Callable
that is expected to take the invocant / argument as its only argument.
(my = 42).snitch = 666; say ; # OUTPUT: «42666»(1..5).snitch; # OUTPUT: «1..5»(1..5).Seq.snitch; # OUTPUT: «(1 2 3 4 5)»(1..5).Seq.snitch(); # OUTPUT: «(1, 2, 3, 4, 5).Seq»(1..5).map(*+1).snitch; # OUTPUT: «(2 3 4 5 6)»say (1..3).Seq.snitch.map(*+2); # OUTPUT: «(1 2 3)(3 4 5)»
The same, using the feed operator:
(1..3).Seq ==> snitch() ==> map(*+2) ==> say(); # OUTPUT: «(1 2 3)(3 4 5)»
Using a custom logger:
my ;my = (1..3).Seq.snitch().map(*+2);say ; # OUTPUT: «[(1 2 3)]»say ; # OUTPUT: «[3 4 5]»