Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: idea for mutiple variadic function Date: Tue, 9 Aug 2016 08:12:00 -0400 Organization: A noiseless patient Spider Lines: 75 Message-ID: References: <5996822c-1276-4b27-88d4-79fcaf551259@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 9 Aug 2016 12:12:05 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="1204"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4SsnnvJy6BpoJrtMekn8/" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <5996822c-1276-4b27-88d4-79fcaf551259@googlegroups.com> Cancel-Lock: sha1:O/d5YPEAueujzNex+f8FQhZk7+4= Xref: csiph.com comp.lang.java.programmer:35235 On 8/9/2016 5:10 AM, Philipp Kraus wrote: > Hello, > > I have got a enum with this structure > > enum myEnum > { > FIRST( > Stream.of( "hello", "foo", "bar" ), > Stream.of( 1, 4, 7 ) > ); > > > private final Map data; > > > myEnum( Stream a, Stream b ) > { > data = Collections.unmodifyableMap( StreamUtils.zip( a, b, (i,j) -> new AbstractMap.SimpleImmutablePair( i, j ) ).collect( Collectors.toMap( i -> i.getKey(), i ->i.getValue() ) ); > } > } > > > I need something like > > myEnum( [ Stream, Stream ], [ Stream, Stream ] .... ) > > tupel of streams with different types but as variadic arguments. > I'm thinking about functional structure but I don't have a very good idea. In my case the streams within a tuple has got equal number of elements. > > Did you have any idea to create a clean constructor parameter definition? Most directly, you could create a class to hold the pair of streams, and make the constructor variadic in the pairs: private static class Pair { private final Stream strings; private final Stream numbers; // ... } FIRST ( new Pair(Stream.of("hello", "foo", "bar"), Stream.of(1, 4, 7) ); myEnum(Pair... pairs) { ... } However, this still leaves the annoying possibility that the two streams of a pair might have different lengths. Why not turn the whole thing inside-out, and deal with String/Number pairs right from the beginning? private static class Pair { private final String string; private final Number number; // ... } FIRST ( new Pair("hello", 1), new Pair("foo", 4), new Pair("bar", 7) ); myEnum(Pair... pairs) { ... } That is, in your example the streams create a problem (length mismatch) and don't appear to offer a benefit -- so why use them? -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM