How to organize related functions that share signature

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to organize related functions that share signature

Ajay
Hi,

Lets say if there are related functions that share signature, then what is the clean way to organize all these functions in one place. Maybe also have this function signature as a type.

An imaginary example,

Functions that increment number: (Int => Int)

def inc(x: Int) = x + 1

def incBy2(x: Int) = x + 2

def incBy3(x: Int) = x + 3

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to organize related functions that share signature

Vlad Patryshev
type IntToInt = Int => Int
val inc: IntToInt = _+1
val incBy2: IntToInt = _+2
val incBy3: IntToInt = _+3

or def incBy(what: Int): IntToInt = _+what

Thanks,
-Vlad

On Wed, Jan 25, 2017 at 2:08 AM, Ajay <[hidden email]> wrote:
Hi,

Lets say if there are related functions that share signature, then what is the clean way to organize all these functions in one place. Maybe also have this function signature as a type.

An imaginary example,

Functions that increment number: (Int => Int)

def inc(x: Int) = x + 1

def incBy2(x: Int) = x + 2

def incBy3(x: Int) = x + 3

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.