I am new to reactive programming and i am looking is that a good practice to perform multiple tasks in single map or i should create separate map for each single operation.
Method 1
Mono.just(new Hashmap())
.map(m -> {m.put("One"); return m;})
.map(m -> {m.put("Two"); return m;})
.map(m -> {m.put("Three"); return m;})
Method 2
Mono.just(new Hashmap())
.map(m -> {
m.put("One");
m.put("Two");
m.put("Three");
return m;
})
So which one is best practice is any performance impact specially?
Let me define it more clearly. I would like to know is that a good practice to type more than one purpose code in one map or i should create map for each purpose like i have a User object now i would like to update its ten fields may me twenty.
so if i use single map my code looks like this.
Mono.just(new User())
.map(user -> {
user.setFirstName("abc");
user.setMiddleName("abc");
user.setLastName("abc");
user.setEmail("abc");
user.setAddress("abc");
// setting twenty more fields.
return user;
});
or should i do each assignment in separate map like this
Mono.just(new User())
.map(user-> {user.setFirstName("abc"); return user;})
.map(user-> {user.setMiddleName("abc"); return user;})
.map(user-> {user.setLastName("abc"); return user;})
//twenty more map function called to set each property
which is the best practice?