可使用 scalaz Arrow 进行组合?
我有两个功能。
def process(date: DateTime, invoice: Invoice, user: User, reference: Reference) : (Action, Iterable[Billable])
def applyDiscount(billable: Billable) : Billable
我怎样才能组合这些,以便我拥有 (DateTime, Invoice, User, Reference) => 的单个函数? (Action, Iterable[Billable])
这是我想要的穷人的方式
def buildFromInvoice(user: User, order: Invoice, placementDate: DateTime, reference: Reference) = {
val ab = billableBuilder.fromInvoice(user, order, placementDate, reference)
(ab._1, ab._2.map(applyDiscount(_))
}
I have two functions.
def process(date: DateTime, invoice: Invoice, user: User, reference: Reference) : (Action, Iterable[Billable])
def applyDiscount(billable: Billable) : Billable
How can I compose these so that I have a single function of (DateTime, Invoice, User, Reference) => (Action, Iterable[Billable])
Here is the poor mans way of what I want
def buildFromInvoice(user: User, order: Invoice, placementDate: DateTime, reference: Reference) = {
val ab = billableBuilder.fromInvoice(user, order, placementDate, reference)
(ab._1, ab._2.map(applyDiscount(_))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所拥有的(简化的)是:
我可以想出几种方法来做到这一点。我认为我的偏好是:
或者也:
但是,可能有一种pointfree方式 - 尽管不一定如此,当然
lift
是Function1W
上的一种方法code> 将函数提升到仿函数的领域 Msecond
是MAB
上的一个方法,它将函数应用到Bifunctor 的右侧
:->
是 Bifunctors 可用的方法,表示函数在 rhs 上的应用。编辑 - missingfaktor 似乎是正确的说法
f andThen g.lift[M].second
有效:Pointfree:
What you have (simplifying) is:
I can think of a few ways of doing this. I think my preference is:
Or also:
However, there is possibly a pointfree way - although not necessarily so, of course
lift
is a method onFunction1W
which lifts the function into the realm of the functor Msecond
is a method onMAB
which applies the function down the right-hand-side of aBifunctor
:->
is a method available toBifunctors
denoting the application of a function on the rhs.EDIT - missingfaktor appears to be correct in saying
f andThen g.lift[M].second
works:Pointfree: