“With” statement equivalent for Scala?

前端 未结 6 903
野的像风
野的像风 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:40

    class Tap[A](underlying:A){
       def tap[B](func: A=>B) = func(underlying)
    }
    
    implicit def anyToTap[A](underlying:A)=new Tap(underlying)
    
    n.child.tap{x =>
       ( x.size > 0 ) &&
       ( x.filter( ! _.isInstanceOf[Text] ).size == 0 )
    }
    

提交回复
热议问题