如何在coffeescript中进行类似于python的元组比较?

如何在coffeescript中进行类似于python的元组比较?,coffeescript,Coffeescript,这是一个我的函数 st3 = (x, y) -> console.log "#{x?}, #{y?}" if [x?, y?] is [true, true] # <- this is the line 'good' 'bad' 我希望能够像在python中一样进行元组比较 在python中,if可以大致写为 if (x, y) == (True, False): return 'good' coffescriptif循环被翻译成javascrip

这是一个我的函数

st3 = (x, y) ->
  console.log "#{x?}, #{y?}"
  if [x?, y?] is [true, true]   # <- this is the line
    'good'
  'bad'
我希望能够像在python中一样进行元组比较

在python中,
if
可以大致写为

 if (x, y) == (True, False):
   return 'good'
coffescript
if
循环被翻译成javascript

if ([x != null, y != null] === [true, true]) {
  'good';
}
这就是为什么这不会被评估为真


有没有其他方法可以用coffeescript来表达呢?

如果您想检查所有参数是否都是
None
,那么我会这样做:

def check_all(*args):
    return all(arg is not None for arg in args)
如果您想检查它们是否都是
真的
(就像字面上的真的一样),那么您可以使用

def check_all(*args):
    return all(arg is True for arg in args)

如果你想要一份清单(如果x为真,y为真,你就不能使用
吗?

在这种情况下是肯定的。但是如果元组大小增加怎么办?我正在寻找一个更优雅的解决方案。这里没有什么不优雅的,如果你有任意大小的参数,你可以循环参数并计算条件。)或者,您可以编写自己的元组原型并从中进行扩展。
def check_all(*args):
    return all(arg is True for arg in args)