• Post Reply Bookmark Topic Watch Topic
  • New Topic

in need of a real functional way

 
Piet Souris
Rancher
Posts: 1638
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I have a List<Integer> initialState, and a List<Move> moves.
'Move' is an interface, having the method List<Integer> change(List<Integer> list),
with several implementations.

What I want to do is to go from the initialState to the endState, by applying
each move in the 'moves' list in succession to the initialState.

Now, a reduce seems ideal for this, but I have the requirement that I also
must store each in-between value.

First thing I tried was:



That worked, but I cannot call this very functional. So I tried this reduce:



That also works, but I find it still ugly. So my question is:

is there a true functional way to achieve what I need, which is also elegant?

Thanks!

Greetz,
Piet
 
Piet Souris
Rancher
Posts: 1638
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, never mind, I changed the program slightly so it is no longer relevant.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!