- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Don't repeat yourself, how to
Wed, 2011-12-14, 12:14
Dear all,
I need to provide a certain number of methods which should available in two signatures:
def myMethod(template:T)
def myMethod(realItem:T, templateGenerator:(T)=>T)
Of course one can do the following
def myMethod(realItem:T, templateGenerator:(T)=>T) = myMethod(templateGenerator(realItem));
Is there a best way to do it, with implicit conversions? (My parameter list is tipically much longer)
Thank you very muchBest Regards
Edmondo
I need to provide a certain number of methods which should available in two signatures:
def myMethod(template:T)
def myMethod(realItem:T, templateGenerator:(T)=>T)
Of course one can do the following
def myMethod(realItem:T, templateGenerator:(T)=>T) = myMethod(templateGenerator(realItem));
Is there a best way to do it, with implicit conversions? (My parameter list is tipically much longer)
Thank you very muchBest Regards
Edmondo
Wed, 2011-12-14, 15:21
#2
Re: Don't repeat yourself, how to
On 14/12/11 21:14, Edmondo Porcu wrote:
> Dear all,
>
> I need to provide a certain number of methods which should available in two
> signatures:
>
> def myMethod(template:T)
>
> def myMethod(realItem:T, templateGenerator:(T)=>T)
>
> Of course one can do the following
>
> def myMethod(realItem:T, templateGenerator:(T)=>T) =
> myMethod(templateGenerator(realItem));
>
>
> Is there a best way to do it, with implicit conversions? (My parameter list
> is tipically much longer)
>
>
> Thank you very much
> Best Regards
>
> Edmondo
>
def myMethod(realItem: T, templateGenerator: T => T = t => t)
Don't overload methods, not ever.
On Wed, Dec 14, 2011 at 12:14 PM, Edmondo Porcu <edmondo.porcu@gmail.com> wrote:
def myMethod[T](realItem:T, templateGenerator:T=>T = identity _)
--
Viktor Klang
Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts
Twitter: @viktorklang