Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33474

Re: Stream FlatMap

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Stream FlatMap
Date 2016-01-18 18:18 -0500
Organization A noiseless patient Spider
Message-ID <n7jrn9$qc7$1@dont-email.me> (permalink)
References <39a5793c-6a65-4402-9c11-69667a03f11d@googlegroups.com> <flatten-20160118182917@ram.dialup.fu-berlin.de> <n7jnv4$peu$1@news.albasani.net>

Show all headers | View raw


On 1/18/2016 5:11 PM, Sebastian wrote:
> Am 18.01.2016 18:29, schrieb Stefan Ram:
>> Philipp Kraus <philipp.kraus.flashpixx@gmail.com> writes:
>>> List<?> x = [1,2, [4,5, ["a", "b"], "c", "d"], ["x", "y"], "z"];
>>> and I would like to flat this list into
>>
>>    The verb is »to flatten«.
>>
>>    The code does not compile:
>>
>> Main.java:38: error: illegal start of expression
>>      List<?> x = [1,2, [4,5, ["a", "b"], "c", "d"], ["x", "y"], "z"];
>>                  ^
>> 1 error
>>
>
> Well, obviously the OP didn't intend that as a list literal, since Java
> does not have them, but as shorthand in pseudo-code.
>
> There's a solution at
> http://rosettacode.org/wiki/Flatten_a_list#Java
>
> It's ugly, does anyone see a way to avoid using instanceof?

     Since he needs to distinguish between "atoms" and things that
need to be flattened recursively, `instanceof' (or a reflective
equivalent) seems unavoidable.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Stream FlatMap Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-18 07:57 -0800
  Re: Stream FlatMap Sebastian <news@seyweiler.dyndns.org> - 2016-01-18 23:11 +0100
    Re: Stream FlatMap Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-01-18 18:18 -0500
  Re: Stream FlatMap Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-01-18 20:34 -0500
    Re: Stream FlatMap Sebastian <sebastian.millies@softwareag.com> - 2016-01-19 04:12 -0800
      Re: Stream FlatMap Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-19 12:15 -0800
        Re: Stream FlatMap Arne Vajhøj <arne@vajhoej.dk> - 2016-01-21 10:12 -0500

csiph-web