Current I should use map method to achieve it:
Source<MyObject, NotUsed> source = Source.single(myObject).map(myObj → {
//1.change internal state of the object
//2.return the object itself
myObj.setInternalState(“newState”)
return myObj;
});
//Any existing method could return the element itself, and receive an “Consumer” that could change the internal state of it. (suppose it’s called xxx)
Source<MyObject, NotUsed> source = Source.single(myObject).xxx(myObj → {
myObj.setInternalState(“newState”);
});