andreak
unread,Feb 28, 2012, 3:27:00 AM2/28/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to functio...@googlegroups.com
In Scala you can do:
scala> List(1, 9, 9, 4, 4, 4, 9, 1, 9, 1, 1, 1, 9).groupBy(v => v);
res6: scala.collection.immutable.Map[Int,List[Int]] = Map(1 -> List(1, 1, 1, 1, 1), 4 -> List(4, 4, 4), 9 -> List(9, 9, 9, 9, 9))
And to do the same using FJ I'm trying this:
List<fj.data.List<Integer>> groupedList = array(1, 9, 9, 4, 4, 4, 9, 1, 9, 1, 1, 1, 9).toList().group(Equal.intEqual);
But that gives me:
for (List<Integer> integers : groupedList) {
System.out.println(integers.index(0) + "\tcount: " + integers.length());
}
1 count: 1
9 count: 2
4 count: 3
9 count: 1
1 count: 1
9 count: 1
1 count: 3
9 count: 1
Im I wrong assuming FJ's group() working like Scala's groupBy?
Thanks to anyone shedding some light on this.
--
Andreas