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


Groups > comp.lang.java.programmer > #34056 > unrolled thread

own stream reduction

Started byPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
First post2016-04-02 07:10 -0700
Last post2016-04-03 08:32 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  own stream reduction Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-04-02 07:10 -0700
    Re: own stream reduction Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-04-02 10:23 -0400
      Re: own stream reduction Sebastian <news@seyweiler.dyndns.org> - 2016-04-02 23:10 +0200
        Re: own stream reduction Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-04-03 08:32 -0700

#34056 — own stream reduction

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2016-04-02 07:10 -0700
Subjectown stream reduction
Message-ID<feb2691d-116f-4519-9c4d-3e01294703aa@googlegroups.com>
Hello,

I try to buld an own reduction stream reduction for my data structure.
I Have create an interface with:

interface Fuzzy<T>
{
    T get();
    double getWeight();
}

So I have build a class with: class FuzzyBoolean implements Fuzzy<Boolean>
I have got a list with IFuzzy<Boolean> objects and I would like to do something like

List<IFuzzy<Boolean>> mylist;
IFuzzy<Boolean> result = mylist.stream().reduce( myfuzzyreducing );

I'm searching for a tutorial or example how I can create an own reduce operator of my own type. 

E.g. an reduction can be something like

Boolean b = true;
double w = 1;

for ( IFuzzy<Boolean> x : mylist )
{
    b = b || x.get();
    w = Math.min(w, x.getWeight());
}

new FuzzyBoolean( b, w );


or another

Boolean b = true;
double w = 0;

for ( IFuzzy<Boolean> x : mylist )
{
    b = b || x.get();
    w = w + x.getWeight()
}

new FuzzyBoolean( b, Math.max(1, w ) );


So I have got different reduction algorithms and would like to use this with the reduce( ) call.
How can I do this with an own streaming reduce structure?

Thanks

Phil

[toc] | [next] | [standalone]


#34057

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-04-02 10:23 -0400
Message-ID<ndokfn$7bb$1@dont-email.me>
In reply to#34056
On 4/2/2016 10:10 AM, Philipp Kraus wrote:
> Hello,
>
> I try to buld an own reduction stream reduction for my data structure.
> [...]
> I'm searching for a tutorial or example how I can create an own reduce operator of my own type.

     The Java Tutorial has a page showing how a few simple reduction
operations can be built "from the ground up:"

http://docs.oracle.com/javase/tutorial/collections/streams/reduction.html

     Also, the Javadoc for java.util.stream has some material that
looks useful.

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

[toc] | [prev] | [next] | [standalone]


#34058

FromSebastian <news@seyweiler.dyndns.org>
Date2016-04-02 23:10 +0200
Message-ID<ndpcgq$rlf$1@news.albasani.net>
In reply to#34057
Am 02.04.2016 16:23, schrieb Eric Sosman:
> On 4/2/2016 10:10 AM, Philipp Kraus wrote:
>> Hello,
>>
>> I try to buld an own reduction stream reduction for my data structure.
>> [...]
>> I'm searching for a tutorial or example how I can create an own reduce
>> operator of my own type.
>
>      The Java Tutorial has a page showing how a few simple reduction
> operations can be built "from the ground up:"
>
> http://docs.oracle.com/javase/tutorial/collections/streams/reduction.html

In particular, as Stream.reduce() is a general-purpose reduction method, 
you don't need to define your own reduction, you just need an 
accumulator. The bodies of the for-loops you have shown are suitable as 
accumulators: They are associative binary operators on Fuzzy<Boolean>.

>      Also, the Javadoc for java.util.stream has some material that
> looks useful.
>

-- Sebastian

[toc] | [prev] | [next] | [standalone]


#34061

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2016-04-03 08:32 -0700
Message-ID<7b79b3b5-fa2a-40a2-900b-d0252549d4b6@googlegroups.com>
In reply to#34058
Am Samstag, 2. April 2016 23:11:07 UTC+2 schrieb Sebastian:
> Am 02.04.2016 16:23, schrieb Eric Sosman:
> > On 4/2/2016 10:10 AM, Philipp Kraus wrote:
> >> Hello,
> >>
> >> I try to buld an own reduction stream reduction for my data structure.
> >> [...]
> >> I'm searching for a tutorial or example how I can create an own reduce
> >> operator of my own type.
> >
> >      The Java Tutorial has a page showing how a few simple reduction
> > operations can be built "from the ground up:"
> >
> > http://docs.oracle.com/javase/tutorial/collections/streams/reduction.html
> 
> In particular, as Stream.reduce() is a general-purpose reduction method, 
> you don't need to define your own reduction, you just need an 
> accumulator. The bodies of the for-loops you have shown are suitable as 
> accumulators: They are associative binary operators on Fuzzy<Boolean>.

Thanks a lot, the hint with the "accumulator" was great.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web