flatmap Questions

1

Solved

Given the following piece of code public static void main(String[] args) { long start = System.currentTimeMillis(); Flux.<Long>generate(s -> s.next(System.currentTimeMillis() - start)...
Zashin asked 4/11, 2017 at 7:32

3

How I can merge List<Map<String,String>> to Map<String,String> using flatMap? Here's what I've tried: final Map<String, String> result = response .stream() .collect(Coll...
Grisby asked 26/10, 2017 at 22:13

1

Solved

I can't figure out how the Scala compiler figures out how to use flatMap with a sequence of Options. If I use a flatMap on a sequence of sequences: println(Seq(Seq(1), Seq()).flatMap(a => a)) ...
Schoening asked 8/10, 2017 at 10:34

3

Solved

scala> List(List(1), List(2), List(3), List(4)) res18: List[List[Int]] = List(List(1), List(2), List(3), List(4)) scala> res18.flatten res19: List[Int] = List(1, 2, 3, 4) scala> res18.fl...
Letti asked 18/11, 2014 at 22:14

2

Solved

Consider the following code: typealias PersonRecord = [String : AnyObject] struct Person { let name: String let age: Int public init(name: String, age: Int) { self.name = name self.age = ag...
Kimberlite asked 22/10, 2016 at 19:17

1

Solved

Can someone explain to me why the .flatMap operator can accept a function which returns an Observable, or an array? The official docs say: The FlatMap operator transforms an Observable by apply...
Gaut asked 22/7, 2017 at 23:59

4

Solved

In Swift, I am trying to flatten an array of dictionaries into one dictionary i.e let arrayOfDictionaries = [["key1": "value1"], ["key2": "value2"], ["key3": "value3", "key4": "value4"]] //the e...
Willawillabella asked 24/2, 2016 at 9:15

1

Solved

flatten Vs flatMap with def method and val function: I defined a def method called toInt: def toInt(s: String): Option[Int] = { try { Some(Integer.parseInt(s.trim)) } catch { case e: Excepti...
Saffron asked 23/4, 2017 at 7:45

2

Solved

How can I convert a Set<Result> into a Map<Item, Set<String>> or SetMultimap<Item, String> using Java 8 streams or Multimaps, where Result is: class Result { String name; ...
Father asked 6/4, 2017 at 4:7

1

Swift documentation of flatMap reads: Returns an array containing the non-nil results of calling the given transformation with each element of this sequence. In the following examples when r...
Riyal asked 13/2, 2017 at 22:41

1

Solved

Given the following as an example of data classes: class Country { List<Region> regions = new ArrayList<>(); List<Region> getRegions() { return regions; } } class Region ...
Paperback asked 9/2, 2017 at 16:52

1

Solved

This is a follow-up to this question: flatMap and `Ambiguous reference to member` error There I am using the following code to convert an array of Records to an array of Persons: let records = /...
Thurber asked 28/11, 2016 at 22:35

3

Solved

I'm trying to use flatmap to make a nested loop with the Stream API, but I can't seem to figure it out. As an example, I want to recreate the following loop: List<String> xs = Arrays.asList(...
Experimentation asked 18/11, 2016 at 13:55

4

Solved

I have an array of Bools and want to edit an array of Scores and an array of Dates for the values that are False. I can't get to it. I thought of getting elements that are false and using that arra...
Centaurus asked 29/9, 2016 at 13:4

2

Solved

I am trying to create all possible pairs of items in a FlatMap: possible_children.clone().flat_map(|a| possible_children.clone().map(|b| (a,b))) In order to do this, I am trying to clone a FlatM...
Cockspur asked 3/9, 2016 at 6:6

1

Solved

I am trying to parse the following JSON: { "String For Key 1": [ "Some String A", "Some String B", "Some String C", ], "String For Key 2": [ "Some String D", "Some String E", "Some Strin...
Semirigid asked 7/8, 2016 at 4:29

2

Solved

let arr: [Int?] = [1,2,3,4,nil] let arr1 = arr.flatMap { next in next } // arr1: [1,2,3,4] let arr2: [Int?] = arr.flatMap { next -> Int? in next } // arr2: [Optional(1), Optional(2), Optional...
Electrometer asked 29/5, 2016 at 3:10

2

Solved

I'm reading the Learning Spark book and couldn't understand the following pair rdd transformation. rdd.flatMapValues(x => (x to 5)) It is applied on an rdd {(1,2),(3,4),(3,6)} and the output ...
Floatage asked 18/5, 2016 at 14:14

1

Solved

I'm using Jupyter Notebook with PySpark. Within that I have a have a dataframe that has a schema with column names and types (integer, ...) for those columns. Now I use methods like flatMap but thi...
Mehala asked 14/5, 2016 at 9:59

5

Solved

If I use xxx.flatMap(_.split(" ")), will it split the array an then flatten or will it flatten and then split?
Whitsuntide asked 12/5, 2016 at 5:8

2

Solved

For example, Vector(Some(1), Some(2), Some(3), None).flatMap{ n => n } produces a Vector(1, 2, 3) instead of giving an error. As I have seen in other languages, flatMap is used when you have...
Themselves asked 12/1, 2016 at 4:2

5

Solved

I have been looking into FP languages (off and on) for some time and have played with Scala, Haskell, F#, and some others. I like what I see and understand some of the fundamental concepts of FP (w...
Solitary asked 12/12, 2015 at 0:19

2

Solved

// given a set of Item objects, group them by the managers of creator and owners Map<String, List<Item>> managersItems = itemSet.parallelStream().flatMap(item -> { // get the list...
Rowan asked 12/10, 2015 at 23:47

2

Solved

I expected to be able to use Stream::flatMap like this public static List<String> duplicate(String s) { List<String> l = new ArrayList<String>(); l.add(s); l.add(s); return...
Toreutic asked 11/9, 2015 at 8:11

1

Solved

My goal is exactly what the title say. What I'm doing is: .stream().flatMap(x -> x.getTitles()) getTitles() returns a LinkedList<String>, and I expected flatMap() to do the job and cre...
Yearly asked 22/6, 2015 at 20:7

© 2022 - 2024 — McMap. All rights reserved.