“With” statement equivalent for Scala?

前端 未结 6 880
野的像风
野的像风 2021-02-13 10:31

Idle pondering from a Scala learner perhaps, but ... in my tinkerings I\'ve written the following:

( n.child.size > 0 ) && ( n.child.filter( ! _.isIns         


        
6条回答
  •  北海茫月
    2021-02-13 10:46

    Starting Scala 2.13, the standard library now provides a chaining operation method pipe fitting exactly this need:

    import scala.util.chaining._
    
    n.child.pipe(list => list.size > 0 && list.filterNot(_.isInstanceOf[Text]).size == 0)
    

    The value of n.child is "piped" to the function of interest.

提交回复
热议问题