Scala forall example?

前端 未结 3 1586
灰色年华
灰色年华 2021-01-31 07:44

I tried Google search and could not find a decent forall example. What does it do? Why does it take a boolean function?

Please point me to a reference (exce

3条回答
  •  一向
    一向 (楼主)
    2021-01-31 08:26

    A quick example of how you can play with this function using a Scala script.

    create a myScript.scala file with

    println(args.forall(p => (p.equals("a"))))
    

    and call it with

    scala myScript.scala a a a  // true
    scala myScript.scala a b c  // false
    

提交回复
热议问题