如何组合方法,没有重复的输入参数 [英] How to compose to methods, without duplicate input arguments

查看:39
本文介绍了如何组合方法,没有重复的输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两种方法

scala> def a(a: Int, b: Int, c: Int) : Int = …
a: (a: Int, b: Int, c: Int)Int

scala> def b(i: Int) : Int = …
b: (i: Int)Int

如何定义一个方法c,即两者的组合?不幸的是,以下代码无法编译:

How to define a method c, that is the composition of both ? Unfortunately, the following code doen't compile :

def c = b(a)

推荐答案

Scalaz 为更高数量的函数定义了 Functor 实例,所以你可以直接编写

Scalaz defines Functor instances for higher-arity functions, so you can just write

(a _).map(b)

这篇关于如何组合方法,没有重复的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆