Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "value without a container" error

Tags:

raku

Got this:

for $config.IO.slurp.lines <-> $l {
  $l .= trim;
  ...
}

Get this:

t/01-basic.rakutest ..3/5
Parameter '$l' expects a writable container (variable) as an argument,
but got '# karabiner config file' (Str) as a value without a container.
  in sub generate_file at...

I've read the docs on containers but it didn't shed any light on what I can do in this situation aside from maybe assigning $l to a scalar variable, which seems hacky. Is there a way I can containerize $l?

like image 249
StevieD Avatar asked Mar 13 '26 20:03

StevieD


1 Answers

The issue is really that .lines does not produce containers. So with <->, you would bind to the value, rather than a container. There are several ways to solve this, by containerizing as you suggested:

for $config.IO.slurp.lines -> $l is copy {
    $l .= trim;
    ...
}

But that only makes sense if you want to do more changes to $l. If this is really just about trimming the line that you receive, you could do this on the fly:

for $config.IO.slurp.lines>>.trim -> $l {
    ...
}

Or, if you need to do more pre-processing $l, use a .map:

for $config.IO.slurp.lines.map({
    .trim.subst("foo","bar",:g)
}) -> $l {
    ...
}
like image 88
Elizabeth Mattijsen Avatar answered Mar 15 '26 14:03

Elizabeth Mattijsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!