groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Sun <>
Subject About LINQ-like DSL for Groovy
Date Sun, 16 Jul 2017 14:01:59 GMT
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 ;)


View this message in context:
Sent from the Groovy Dev mailing list archive at

View raw message