java is not very composable
May. 24th, 2014 06:29 pmDoes anyone know why it is that in Java 8 List.replaceAll doesn't return the list in question (post replacement (or even better, with lazy evaluation waiting to happen))?
That asked, going back before java 8, does anyone know why List.add doesn't return the list? I think the official reason is so that it can always return true so as to implement Collection.list. But that's kind of terrible...
I mean is there a bad reason, or just no reason at all? The entire point of java 8 lambdas is to reduce the amount you have to type...
I'd like this:
System.out.println(new LinkedList().add(1).add(2).replaceAll(i -> i*i).add(3));
to generate this:
[1,4,3]
Instead I have to do this:
List list = new LinkedList<>();
list.add(1);
list.add(2);
list.replaceAll(i -> i*i);
list.add(3);
System.out.println(list);
Is there some java 8 thing I haven't seen yet that might improve this?
That asked, going back before java 8, does anyone know why List.add doesn't return the list? I think the official reason is so that it can always return true so as to implement Collection.list. But that's kind of terrible...
I mean is there a bad reason, or just no reason at all? The entire point of java 8 lambdas is to reduce the amount you have to type...
I'd like this:
System.out.println(new LinkedList
to generate this:
[1,4,3]
Instead I have to do this:
List
list.add(1);
list.add(2);
list.replaceAll(i -> i*i);
list.add(3);
System.out.println(list);
Is there some java 8 thing I haven't seen yet that might improve this?