當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Scala ChainingOps.pipe用法及代碼示例

pipe 方法(或屬性)屬於 scala.util.ChainingOps 類(class),其相關用法說明如下。

用法:

def pipe[B](f: A => B): B

通過應用函數f轉換值.

scala> import scala.util.chaining._

scala> val times6 = (_: Int) * 6
times6: Int => Int = $$Lambda$2023/975629453@17143b3b

scala> val i = (1 - 2 - 3).pipe(times6).pipe(scala.math.abs)
i: Int = 24

注意:與等效的 { val temp = 1 - 2 - 3; times6(temp) } 相比,(1 - 2 - 3).pipe(times6) 在運行時可能會有少量開銷。

類型參數:

B

函數f的結果類型.

值參數:

f

應用於值的函數。

返回:

將給定函數 f 應用於此值而產生的新值.

源碼:

ChainingOps.scala

相關用法


注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 ChainingOps.pipe。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。