groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: [GEP]Lazy evaluation for Groovy 3
Date Sat, 17 Mar 2018 07:40:50 GMT
But we already have @Lazy which is a bit more explicit?

Le sam. 17 mars 2018 à 08:35, Daniel.Sun <sunlan@apache.org> a écrit :

> Hi all,
>
>        Sometimes we do not want evaluate some expression eagerly(Maybe
> evaluation is expensive), e.g. a table contains a field `records` whose
> content is queried from DB, but we do not get the content of `records`
> eagerly util we access `records`.
>
> class SomeTable {
>        def records = ( doQueryFromDB() )   // the expression in the
> parentheses will be evaluated lazily
>        def sum() {
>              // access the methods or fields of `records`, trigger
> evaluation, i.e. the query of DB
>        }
>        def getRecords() {
>              return records // do NOT trigger evaluation
>         }
> }
>
>          Lazy evaluation syntax is very simple( just supports 1) and 2) ):
> 1) def v = ( someExpression() )  // Lazy evaluation for variable
> declaration
> 2)  v = ( someExpression )          // Lazy evaluation for assignment
> 3)  println(( someExpression )) // NOT lazy evaluation
>
>            Any thoughts?
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>

Mime
View raw message