develooper Front page | perl.perl6.users | Postings from September 2017

Re: takeWhile ?

Thread Previous | Thread Next
From:
The Sidhekin
Date:
September 11, 2017 20:14
Subject:
Re: takeWhile ?
Message ID:
CAHAeAG4hGbq1jATFyv5and3NJqoZmS4jiRLE3=mkkMgwaAb-cA@mail.gmail.com
On Mon, Sep 11, 2017 at 10:01 PM, Marc Chantreux <khatar@phear.org> wrote:

> hello,
>
> doing maths with my kid, i just translated his spreadsheet with those
> lines of haskell:
>
>         rebonds height loss = height : rebonds (height - height * loss)
> loss
>         main = print $ takeWhile (> 2) $ rebonds 116 0.6
>
> then i wanted to make it as short as possible in perl6, i'm almost
> there:
>
>         (116, * * .6  ... * < 2 ).say
>
> but the first $_ < 2 remains in the list. the only one alternative i see
> is a gather/take loop but i really expect something shorter from perl6
> :)
>

  Isn't this what ...^ is for?

    (116, * * .6  ...^ * < 2 ).say;


Eirik

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About