But you can also create and pass a function inline: scala> doMath(1,2,(a : Int, b : Int) => a ^ b) res5: Int = 3
On Thu, Jul 30, 2009 at 11:43 PM, Viktor Klang <viktor.kl...@gmail.com>wrote: > Here's a short example: > > val add = (a : Int, b : Int) => a + b > val sub = (a : Int, b : Int) => a - b > val div = (a : Int, b : Int) => a / b > val mul = (a : Int, b : Int) => a * b > > //This is a method that takes an Int a, an Int b and a function that takes > 2 Ints and produces an Int > def doMath(a : Int, b : Int, arith : (Int,Int) => Int) = arith(a,b) > > scala> doMath(1,2,add) > res1: Int = 3 > > scala> doMath(1,2,sub) > res2: Int = -1 > > scala> doMath(2,1,div) > res3: Int = 2 > > scala> doMath(1,2,mul) > res4: Int = 2 > > > On Thu, Jul 30, 2009 at 11:36 PM, ben <b...@primrose.org.uk> wrote: > >> >> Hi, >> >> Thanks for patience (and for the interesting subpost on the diff >> between val & def) ! >> OK, the callback thing you suggested is starting to clear the mist ... >> I found this article : >> http://www.ibm.com/developerworks/java/library/j-scala01228.html >> I've not had time to read it fully yet, as its getting late over here >> in the UK, but it looks like what I'm after. I'll have a proper read >> tomorrow. >> >> Thanks again for your time. >> >> Ben >> >> >> >> > > > -- > Viktor Klang > > Rogue Scala-head > > Blog: klangism.blogspot.com > Twttr: viktorklang > -- Viktor Klang Rogue Scala-head Blog: klangism.blogspot.com Twttr: viktorklang --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---