stdout
of the forEach method is a 'positional' argument, the second argument stderr
is a named argument. The stdout
argument is required whilst the stderr
argument is optional.LineAction
is a Dart typedef
that declares that LineAction is a function that takes a single String.typedef LineAction = void Function(String line);
stdout
and optionally the second argument stderr
.(line) => print(line)
(<args>) => <expression>
stdout
positional argument is of type LineAction
. The LineAction
function takes a String as its only argument. So in this case (<args>)
is a single argument of type String.forEach
method will call the Lambda function each time the tail
command outputs a line. The value of that line will be contained in the line
argument passed to your Lambda.=>
operator, sometimes referred to as a 'fat arrow'. Essentially the =>
operator passes the line
argument to the <expression>
;<expression>
.<expression>
can be any valid Dart expression. In the above example the expression is print(line)
which prints the contents of line
to the console.<expression>
is that it must be a single line expression. Our LineAction
is declared as returning a void so in our case the return value of the expression is ignored.return
statement if you want to return something from the Lambda.(args) { <statements> }
stderr
when interacting with the forEach
method.