Request for Terminology: object-functional twist on function currying

14 views
Skip to first unread message

Brian Maso

unread,
Dec 23, 2014, 1:30:56 PM12/23/14
to dispatc...@googlegroups.com
I'm looking for a name for a somewhat common refactoring I do in my Scala code. In this pattern I will "raise" a class' common method parameter up to being a member variable. For example:

\\ Original type:

trait Customer {
    def name(as_at: Date): String
    def address(as_at: Date): Address
    //...imagine other methods with explicit "as_at: Date parameters...
}

\\ Refactored type -- the as_at: Date method parameter up to a member

trait Customer {
  val as_at: Date

  def name: String
  def address: Address
  //...other methods refer to the as_at: Date member internally
}


There's obvious inverse/dual, where you would "lower" an instance member to a method parameter. For example:

// Original type

trait Mortgage {
  val interestRate: Double

  def marturityDate: Date = {
    //...calculation uses the interestRate val
  }
}

// Refactored:

trait Mortgage {
  def maturityDate(interestRate: Double): Date = ...
}


When I do this refactor, it feels lot like currying, though obviously its not the same thing as currying. I'm toying with the term "closing state over a common method parameter", but that seems a little long. And I guess I'd have to call the inverse "unclosing state to a common method parameter" if I were sticking to my terminology. Ick. No.

Any suggestions?

--
Best regards,
Brian Maso
(949) 395-8551
Follow me: @bmaso
br...@blumenfeld-maso.com

eugene yokota

unread,
Dec 23, 2014, 1:51:00 PM12/23/14
to dispatc...@googlegroups.com
Not sure if this topic is Dispatch specific.
I skimmed through Refactoring and found "Convert Procedural Design to Objects."
If that sounds too pro-OO circa 1999, you can say "Convert Functional Design to Objects."

-eugene

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

Brian Maso

unread,
Dec 23, 2014, 6:13:15 PM12/23/14
to dispatc...@googlegroups.com
Oh shoot! I had meant to send that to scala-user -- please pardon the noise

Brian Maso
Reply all
Reply to author
Forward
0 new messages