Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Reducer' - 2 code snippet(s) found

 Sample 1. Get the Maximum number out of the Integer List, using Lambda Expression

// Declare and Initialize the Collection

List<Integer> intList = new ArrayList<Integer>();

// Add Elements

intList.add(1);
intList.add(2);
intList.add(3);
intList.add(4);


System.out.println(intList.stream().reduce(Math::max).get()); // Prints 1

   Like      Feedback     lambda expression   collections   set  hashset  generics  stream  reducer   Math::max


 Sample 2. Ngrx Reducer method , State interface and Initial state variable

export interface IAppState{
myNumber: number;
}

export const INITIAL_STATE: IAppState = {
myNumber: 0
}

export function reducer(state,action){

if(action.type == INCREMENT){

let num:number[] = state.myNumber;
let num1:number = num.length + 1;

return Object.assign({},...state,{
myNumber: state.myNumber + 1
})
} else {
return state;
}
}

   Like      Feedback     Ngrx



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus