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.

296 questions
442
votes
6 answers

Difference between map and collect in Ruby?

I have Googled this and got patchy / contradictory opinions - is there actually any difference between doing a map and doing a collect on an array in Ruby/Rails? The docs don't seem to suggest any, but are there perhaps differences in method or…
sscirrus
  • 50,379
  • 41
  • 125
  • 211
203
votes
7 answers

Extract a dplyr tbl column as a vector

Is there a more succinct way to get one column of a dplyr tbl as a vector, from a tbl with database back-end (i.e. the data frame/table can't be subset directly)? require(dplyr) db <- src_sqlite(tempfile(), create = TRUE) iris2 <- copy_to(db,…
nacnudus
  • 5,420
  • 5
  • 30
  • 46
68
votes
7 answers

what's different between each and collect method in Ruby

From this code I don't know the difference between the two methods, collect and each. a = ["L","Z","J"].collect{|x| puts x.succ} #=> M AA K print a.class #=> Array b = ["L","Z","J"].each{|x| puts x.succ} #=> M AA K print b.class #=> Array
mko
  • 19,044
  • 43
  • 119
  • 183
65
votes
1 answer

Collect values from an array of hashes

I have a data structure in the following format: data_hash = [ { price: 1, count: 3 }, { price: 2, count: 3 }, { price: 3, count: 3 } ] Is there an efficient way to get the values of :price as an array like [1,2,3]?
Kert
  • 1,359
  • 3
  • 13
  • 14
51
votes
2 answers

pyspark collect_set or collect_list with groupby

How can I use collect_set or collect_list on a dataframe after groupby. for example: df.groupby('key').collect_set('values'). I get an error: AttributeError: 'GroupedData' object has no attribute 'collect_set'
Hanan Shteingart
  • 6,354
  • 6
  • 42
  • 56
41
votes
2 answers

Static context cannot access non-static in Collectors

I have group of students. First I want to group them by the marks. Then I want to further group those sets into same name students together. Map>> groupping = students.stream() …
Jude Niroshan
  • 3,973
  • 6
  • 36
  • 53
37
votes
8 answers

Scala Partition/Collect Usage

Is it possible to use one call to collect to make 2 new lists? If not, how can I do this using partition?
Adrian Modliszewski
  • 1,074
  • 2
  • 17
  • 30
33
votes
2 answers

Java 8 is not maintaining the order while grouping

I m using Java 8 for grouping by data. But results obtained are not in order formed. Map> groupedResult = null; if (!CollectionUtils.isEmpty(groupByColumns)) { Map mapArr[] = new…
Shreya Shah
  • 423
  • 1
  • 4
  • 14
30
votes
2 answers

ruby using the "&:methodname" shortcut from array.map(&:methodname) for hash key strings rather than methodname

Most ruby developers know how to save a few keystrokes by doing something like this: array.map(&:methodname) rather than array.map {|x| x.methodname } Is there any way I could apply a similar &:methodname shortcut for calling "methods" (values…
boulder_ruby
  • 33,076
  • 8
  • 66
  • 91
26
votes
2 answers

Linq Map! or Collect!

What is the Linq equivalent to the map! or collect! method in Ruby? a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] I could do this by iterating over the collection with a foreach, but I…
Jason Marcell
  • 2,605
  • 5
  • 27
  • 39
23
votes
2 answers

How to use collect call in Java 8?

Lets say we have this boring piece of code that we all had to use: ArrayList ids = new ArrayList(); for (MyObj obj : myList){ ids.add(obj.getId()); } After switching to Java 8, my IDE is telling me that I can replace this code with…
Alexandru Severin
  • 5,268
  • 9
  • 38
  • 63
22
votes
1 answer

Collect only if result is not null

I have a collection and I'm wanting to find certain elements and transform them. I can do this in two closures but I was wondering if it is possible with only one? def c = [1, 2, 3, 4] def result = c.findAll { it % 2 == 0 } result =…
Lerp
  • 2,627
  • 3
  • 20
  • 39
19
votes
9 answers

Map an array modifying only elements matching a certain condition

In Ruby, what is the most expressive way to map an array in such a way that certain elements are modified and the others left untouched? This is a straight-forward way to do it: old_a = ["a", "b", "c"] # ["a", "b", "c"] new_a…
Yang Meyer
  • 4,909
  • 4
  • 37
  • 51
15
votes
2 answers

Spark: Difference between collect(), take() and show() outputs after conversion toDF

I am using Spark 1.5. I have a column of 30 ids which I am loading as integers from a database: val numsRDD = sqlContext .table(constants.SOURCE_DB + "." + IDS) .select("id") .distinct .map(row=>row.getInt(0)) This is the…
Christos Hadjinikolis
  • 1,723
  • 2
  • 17
  • 39
15
votes
1 answer

How to collect DoubleStream to List

I have the following code: Stream.of("1,2,3,4".split(",")).mapToDouble(Double::valueOf).collect(Collectors.toList()); I want to return List. This code doesn't compile. I see error: Error:(57, 69) java: method collect in interface…
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
1
2 3
19 20