There's more than one way to do things PerlMonks

### Re: Thoughts on some new operators for perl (6 or 7)

 on Mar 10, 2004 at 22:26 UTC ( #335639=note: print w/replies, xml ) Need Help??

You shouldn't necessarily assume you have to loop at all. Perl 6 also lets you take a junctional approach:
```    \$lowest  = one(@list_of_int) <= all(@list_of_int);
\$highest = one(@list_of_int) >= all(@list_of_int);
\$lowest  = one(@list_of_int) le all(@list_of_string);
\$highest = one(@list_of_int) ge all(@list_of_string);
Or something like that...

Replies are listed 'Best First'.
Re^2: Thoughts on some new operators for perl (6 or 7)
by lidden (Curate) on Mar 22, 2008 at 00:16 UTC
one(@list_of_int) <= all(@list_of_int)

Shouldn't that be true if the lowest value is a dupe and false if not?

Now four years later I think what the op wanted is best written:

```my \$lowest = [min] @list_of_int;
Yes, though we didn't have reduce operators back then, nor did we have infix min and max that would allow you to say
```for @list {
\$min min= \$_;
\$max max= \$_;
}
But [minmax] @list might be what the OP really wants.

And to answer tye's question, min and max are multiply dispatched, so it depends on the types of each pair of arguments. Non-comparable values probably produce an error, but any ordered type will work if used consistently.

(And my grandparent response was probably bogus, since junctions are really only for doing boolean logic, not pulling out actual values. But given that I was very sick four years ago, I'm not surprised...)

I assume that one() isn't the same as any().

So is "min" numeric or alpha?

- tye

Create A New User
Node Status?
node history
Node Type: note [id://335639]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-06-24 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (560 votes). Check out past polls.