Skip to content

Example code for andthen docs occasionally returns error: Attempt to return outside of any Routine #4398

@jubilatious1

Description

@jubilatious1

Example code for andthen docs occasionally returns error: Attempt to return outside of any Routine

https://docs.raku.org/routine/andthen

sub load-data {
    rand  > .5 or return; # simulated load data failure; return Nil 
    (rand > .3 ?? 'error' !! 'good data') xx 10 # our loaded data 
}
load-data.first: /good/ andthen say "$_ is good"; # OUTPUT: «(good data is good)␤» 
 
load-data() andthen .return; # return loaded data, if it's defined 
die "Failed to load data!!";

Returns (sample):

===11/10/23 11:55:27===
Use of Nil in string context
  in block <unit> at - line 5
Failed to load data!!
  in block <unit> at - line 8

===11/10/23 11:55:32===
good data is good
Failed to load data!!
  in block <unit> at - line 8

===11/10/23 11:55:38===
Use of Nil in string context
  in block <unit> at - line 5
Attempt to return outside of any Routine
  in block <unit> at - line 7

The Attempt to return outside of any Routine error above seems to distract from the main point of the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions