更新时间:2023-11-23 14:20:40
另一个有趣的解决方案是:
Just another interesting solution:
filterM (const [True,False]) [1,2,3]
我读取如下:返回包含或不包含列表元素的可能组合。这个解释可能不会使用正确的术语,但是我直观地理解它。对于每个元素, const
的计算结果为 [True,False]
,因此每个元素都包含在或不包含在结果中。使用 filterM
,这里的谓词位于monad列表中,所以我们得到了可能结果的列表。
I read this as follows: Return the possible combinations of including or not including an element of the list. This explanation might not be using the correct terminology, but it's how I intuitively understand it. const
evaluates to [True,False]
for every element, so every element is included or not included in the result. Using filterM
, the predicate here is in the list monad, so we get a list of the possible results.