combine in 0.7

51 views
Skip to first unread message

Alex Cozzi

unread,
Apr 5, 2013, 11:44:43 AM4/5/13
to scoobi...@googlegroups.com
Moving my code to 0.7, I used to do, using scalaz:

 val items : DList(Long, (Int, Int)) = ...

 val grouped: DList[(Long, (Int, Int))] = items.groupByKey.combine { _ |+| _ }


But in 0.7 + Scala 2.10 I get an error and I think I need to do:


  val grouped: DList[(Long, (Int, Int))] = items.groupByKey.combine { Sum.int zip Sum.int }


Is there a better/more convenient way to sue Reductions?

Elliot Chow

unread,
Apr 6, 2013, 3:39:57 PM4/6/13
to scoobi...@googlegroups.com
I have been cheating a bit by using an implicit conversion:

implicit def funToReduction[A](f: (A,A) => A) = new Reduction[A]{ val reduce = f }

Would love to know if there is a better way.

Eric Springer

unread,
Apr 6, 2013, 4:05:32 PM4/6/13
to scoobi...@googlegroups.com
I just add a layer of 'Reduction' in, e.g.:

dlist.combine(Reduction(_ |+| _))


But I do feel like having an implicit conversion of (A, A) => A to Reduction[A] would be useful, although I'm not aware of the design goals behind the new combine api, and what it fixes



--
You received this message because you are subscribed to the Google Groups "scoobi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scoobi-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eric Springer

unread,
Apr 6, 2013, 4:21:24 PM4/6/13
to scoobi...@googlegroups.com
I've now adopted your little trick in my code. It's pretty useful for source-compatibility too, when flipping between 0.6 and 0.7 xD

On Sat, Apr 6, 2013 at 12:39 PM, Elliot Chow <chow....@gmail.com> wrote:

Eric Torreborre

unread,
Apr 7, 2013, 8:55:38 PM4/7/13
to scoobi...@googlegroups.com
Hi Alex,

the Reduction datatype is supposed to provide lots of useful combinators in order to write "combine" functions.

I thought that we had something to create a Reduction from a Semigroup but I couldn't find it so I added it here:

https://github.com/NICTA/scoobi/commit/6505a94f30a0b4c0a34b36be93904a5d0e6a48f1. Your example then becomes:

items.groupByKey.combine(semigroup)

Cheers,

Eric.
Reply all
Reply to author
Forward
0 new messages