本文介绍了将逻辑和应用于布尔值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下Scala中的布尔值列表

Consider the following list of Boolean values in Scala

List(true, false, false, true)

您如何使用foldRight或foldLeft来模拟对列表中的所有值执行逻辑与的功能?

How would you using either foldRight or foldLeft emulate the function of performing a logical AND on all of the values within the list?

推荐答案

val l = List(true, false, false, true)
val andAll = l.foldLeft(true)(_ && _)

这篇关于将逻辑和应用于布尔值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 00:41