This seems very un-Java - surely the Java way to achieve this would be method overloading.
This seems very un-Java - surely the Java way to achieve this would be method overloading.
seq.shuffle(); // copy to a new seq and shuffle it
seq.shuffle$(); // shuffle the original seq
These two methods should have the exact same signature. So using two different names is necessary. I'm not particularly fond of introducing $ as a substitute for !. That convention is not existent in Java, and is not at all obvious to anyone who hasn't studied a functional language.I would probably solve this by simply making shuffle always in place, and add a copy constructor and/or copy method:
// Copy and shuffle.
(new Seq(seq)).shuffle();
seq.copy().shuffle();
// Shuffle in-place.
seq.shuffle();I would greatly prefer this approach - it is clear, consistent with common java practices, and self-documenting: you don't even really need to know java to understand what this does.
I probably would have gone with shuffleInPlace(), but the more I think about it, the more I like the $. Especially since it will rarely get used.
This library is pretty neat largely because it changes some common (and annoying) java idioms.
I do agree $ is very un-Java, either.
But I don't want "shuffle" to be in-place method by default. I agree with @jdmichal that it should return new copy.
In this case how to design the in-place way is not obvious.
I'm the main author of fig. This project is started for just a week. All of your suggestion are very supportive and I'm checking the feedback to make fig better.
See underscore or scala for inspiration.