Open Icelandjack opened 7 years ago
Giving
allEqual :: (Foldable f, Eq a) => f a -> Bool
allEqual = allEqualOf folded
You'll want to put the Nope
matches at the top, so Nopes propagate quicker. Nope <> _ = Nope
means that it can completely ignore searching on the right if the left returns a negative result.
On the plus side its fairly easy to implement. On the downside, we tend to avoid fooBar style names in lens, with the exception of 'Of' so the name seems a bit off for us.
The naming omniequalOf
would avoid the fooBar
problem at the probable cost of clarity.
Even though it's not in
Data.List
it would be cool to have aFold
for testing if all elements are the same. Sketch of an implementation, comment if you have a nicer way of constructing thisMonoid
, maybe withFirst
andAll
Other names
allSameOf
,allEqualOf
,equalOf
,allTheSameOf
.