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


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

Re: idea for mutiple variadic function

Newsgroups comp.lang.java.programmer
Date 2016-08-25 16:21 -0700
References <5996822c-1276-4b27-88d4-79fcaf551259@googlegroups.com> <nochak$15k$1@dont-email.me>
Message-ID <4b9e4d08-0fc0-4e88-a213-72d0177dd3c6@googlegroups.com> (permalink)
Subject Re: idea for mutiple variadic function
From Philipp Kraus <philipp.kraus.flashpixx@gmail.com>

Show all headers | View raw


Thanks for the tip with pairs, I'm using pairs but I get two streams from another method, so in this case i need to concat the stream. For the concatination I'm using protonpack with StreamUtils and the length is checked.

I'm think about a good and easy API call

Phil

Am Dienstag, 9. August 2016 14:12:17 UTC+2 schrieb Eric Sosman:
> 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<String,Number> data;
> >
> >
> >      myEnum( Stream<String> a, Stream<Number> 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<String>, Stream<Number> ],  [ Stream<Integer>, Stream<String> ] .... )
> >
> > 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<String> strings;
> 	    private final Stream<Number> 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

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


Thread

idea for mutiple variadic function Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-08-09 02:10 -0700
  Re: idea for mutiple variadic function Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-09 08:12 -0400
    Re: idea for mutiple variadic function Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-08-25 16:21 -0700

csiph-web