groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: About LINQ-like DSL for Groovy
Date Sun, 16 Jul 2017 14:56:39 GMT
I did something similar in the Gaelyk DSL for accessing the datastore. Our
command chain expressions make things pretty readable and SQL like. Now it
would be good to also see how it looks like for non trivial examples, like
complex where clauses, sub-queries and the like.

Le 16 juil. 2017 4:02 PM, "Daniel Sun" <realbluesun@hotmail.com> a écrit :

> Hi all,
>
>        Although Groovy and Java 8+ can handle data structure easily, it is
> still less easier and readable than LINQ IMHO.
>        I tried to implement it at the language level and found too many
> keywords will be introduced to Groovy, so I think LINQ-like DSL will be
> more
> feasible. e.g.
>
>         def nums = [0, 1, 2, 3]
>
>         // command chain expression can not span rows, so we can use
> closure
> to wrap expressions
>         def numQuery =  linq {    // numQuery is an Iterator<Integer>
>             from num of nums       // in is a keyword of groovy, so use of
> instead. Maybe some other word is better?
>             where num % 2 == 0
>             select num
>          }
>
>          for (num in numQuery) { /* do with the result */ }
>
> Note: linq, from, of, where, select are all methods and others are their
> parameters. Beside the basic use case, joining, grouping etc. are all in
> the
> TODO list :)
>
>         The DSL will be a big work, it will last long. Before I find some
> time to working on it, I wish you like the LINQ-like DSL idea, although it
> is not mature enough for the time being ;)
>
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/About-LINQ-like-DSL-for-Groovy-tp5742132.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
>

Mime
View raw message