2

Since Swift supports Java Stream interface/methods (map, filter, reduce, etc.) by default for Arrays I was wondering if there is support for parallel execution like in java?

E.g.

[1,2,3].parallel().map { x -> x*2 }.filter { x -> condition(x) } etc.

In Java if streams are "programmed correctly", meaning the combiner phase is done right, then parallelizing the work is very easy, by just adding parallel() call in the chain.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
denis631
  • 1,765
  • 3
  • 17
  • 38
  • @StephenC wanted to relate to java streams, this is why java was in tag list – denis631 Nov 14 '17 at 11:35
  • 2
    I know that's what you wanted to do. But (IMO) that is incorrect use of tags. You use tags when the question is *about* the tag, not when it relates to it. The point is that tags are to help people refine their searches. People will use "java" as a refinement when what they are trying to find an answer for is about Java. Tags are also used by other people to look for questions that they are interested in answering. – Stephen C Nov 14 '17 at 11:48
  • So ... in your case ... other people who are likely to find your question and any answers useful will be searching for how to do parallel streams in "[swift]". And Swift experts will be looking for "[swift]" questions to answer. But if you tag the Q with "[java]" as well then it will *also* show up for people wanting to know how to do parallel stream processing in Java, and Java experts looking for questions to answer. These are going to be **false hits**. – Stephen C Nov 14 '17 at 11:54
  • @MartinR I don't consider it to be the answer to my question, because it explains only map function, whereby I'm talking about generalized approach. For example reduce should have combiner phase, like Java. Read this (https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html) for more info – denis631 Nov 16 '17 at 11:46
  • @denis631: First, *"Swift supports Java Stream interface"* makes no sense because that are two different languages. Second, Swift itself has no multithreading/async/parallel/... support *at all* (it is planned for a future version). One can use libdispatch (aka GCD) from Swift, and `concurrentPerform` seems to be the closest to what your are looking for. – So I am not sure what answer you expect. But I'll reopen the question to avoid arguments about that. – Martin R Nov 16 '17 at 12:30
  • 1
    @MartinR "makes no sense" is a very subjective opinion. I've written it, so that people can relate to the problem better, if they have experience with java streams – denis631 Nov 16 '17 at 13:45
  • @MartinR I guess link to the swift-evolution discussion about parallelization of map/reduce functions in swift is a valid answer (if there is any link to that discussion) – denis631 Nov 16 '17 at 13:49
  • That is about concurrency in general (targeted for Swift 5?). Discussion starts here https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170814/038892.html. – Martin R Nov 16 '17 at 13:53

0 Answers0