Questions tagged [collect]

Use this tag for questions related to the act of gathering/collecting/grouping data/results from several nodes/places/computers to one (or main) resource(s).

Use this tag for questions related to the act of gathering/collecting/grouping data/results from several nodes/places/computers to one (or main) resource(s).

For example, in Distributed Computing, the slaves would do their local computation and eventually, one would like the master to collect the (local) results.

354 questions
6
votes
3 answers

How to make Groovy / Grails return a List of objects instead of a List of Lists of objects?

I have a class like this: class Foo { static hasMany = [bars: Bar] } When I write: Foo.getAll() I get a list of Foo objects like this: [ Foo1, Foo2, Foo3 ] When I write: Foo.getAll().bars I get a list of lists of Bar object like this: [ […
ubiquibacon
  • 10,451
  • 28
  • 109
  • 179
5
votes
3 answers

Private Sorting Rule in a Stream Java

Hey if anyone has an idea I would be really thankfull. I'm in a Java stream and i would like to sort my list that i'll be returning. I need to sort the list via TradPrefis ( MyObject::getTradPrefix ). But this would be way too easy. Because i want…
5
votes
2 answers

What is the jq equivalent for the slurp option?

This generates a list of arrays: $ echo -e "a 1\nb 2" | jq -R 'split(" ")' [ "a", "1" ] [ "b", "2" ] When I slurp the input I get an array: $ echo -e "a 1\nb 2" | jq -R 'split(" ")' | jq -s . [ [ "a", "1" ], [ "b", …
ceving
  • 21,900
  • 13
  • 104
  • 178
5
votes
1 answer

java 8 groupingBy list of list

Let say we have an object Draw: class Draw { private int num1, num2, num3; public Draw (int num1, int num2, int num3) { this.num1 = num1; this.num2 = num2; this.num3 = num3; } public int getNum1() { return num1; } public void…
EasyRider
  • 149
  • 2
  • 9
5
votes
2 answers

Java lambdas: Copy nodes from list to a new list

I am quite new to Java lambdas, and I am not sure if what I want is achievable: I have a list of objects, which I'd like to filter to extract those of them that are matching a given condition, and put them in a separated list (so I can perform some…
motagirl2
  • 589
  • 1
  • 10
  • 21
5
votes
1 answer

Java 8 collect vs reduce

As known, when doing the accumulation, "reduce" always returns a new immutable object while "collect" will make changes on a mutable object. However when I accidentally assign one method reference to both reduce and collect method, it compiles…
ning
  • 61
  • 4
5
votes
1 answer

Using collect closure method to populate a HashMap in groovy

I am trying to populate a Map from an List. Here's what I am doing. itemNoList = [1,2,3,4] bookMap = [:] bookMap = itemNoList.collect{ [ (it) : it+1 ] } When I do this, the bookMap changes to ArrayList type and now has a List of HashMap. bookMap is…
Wizard
  • 1,154
  • 2
  • 14
  • 41
5
votes
6 answers

How to tweak LISTAGG to support more than 4000 character in select query?

Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production. I have a table in the below format. Name Department Johny Dep1 Jacky Dep2 Ramu Dep1 I need an output in the below format. Dep1 - Johny,Ramu Dep2 - Jacky I…
anuu_online
  • 374
  • 1
  • 3
  • 14
4
votes
1 answer

Function::identity doesn't work in Collectors.toMap

I am trying to turn a List into a Map, with the value of the map being an element contained within the previous List, and the key being some attribute of that String (for example, the length of the String, in which case, T…
davidalayachew
  • 1,279
  • 1
  • 11
  • 22
4
votes
2 answers

How do pattern match assignments in for comprehensions translate into monadic operations?

I am familiar with the concept that Scala's for comprehensions are just syntactic sugar for monadic operations (map, withFilter, foreach, and flatMap) and the desugaring is described in this popular answer. By that logic, I was surprised to find…
Ian
  • 5,704
  • 6
  • 40
  • 72
4
votes
2 answers

How does the Iterator::collect function work?

I am trying to understand the full capabilities of collect function by going through some documentation. I am running into some challenges, specifically in the last example quoted on the page (also listed below, with my comments inline) let results…
Late Nighter
  • 69
  • 1
  • 1
  • 6
4
votes
1 answer

How do I get SymPy to collect partial derivatives?

I have been using SymPy to expand the terms of a complex partial differential equation and would like to use the collect function to gather terms. However, it seems to have a problem dealing with second (or higher order) derivatives where the…
4
votes
2 answers

Java 8 stream, how to "break" in reduce or in collect without throwing runtime exception?

This question have been asked in a context of forEach. Comment(after the answer was accepted): I accepted the answer of @nullpointer, but it is the right one only in the context of my code example, not in the general question about break-ability of…
Vladimir Nabokov
  • 1,797
  • 1
  • 14
  • 19
4
votes
2 answers

Map and Groupby in one go

I have a model class as follows: public class CCP implements Serializable{ private static final long serialVersionUID = 1L; @Id @Column(name = "p_id") private Integer pId; @Id @Column(name = "c_id") private Integer…
KayV
  • 12,987
  • 11
  • 98
  • 148
4
votes
1 answer

Java 8 Stream, How to get Top N count?

I need your advice to simplify this code below. I have a player list with an ID of the games won. I want to extract the 2 best players from this list (the 2 players who have a better amount of match Id) Once extracted, I have to return the initial…
anthony44
  • 345
  • 1
  • 4
  • 15
1 2
3
23 24