Skip to content

Instantly share code, notes, and snippets.

@BillWagner
Created July 28, 2016 15:54
Show Gist options
  • Save BillWagner/b638cb3d7e2f77c8ae3e371eda1b6b04 to your computer and use it in GitHub Desktop.
Save BillWagner/b638cb3d7e2f77c8ae3e371eda1b6b04 to your computer and use it in GitHub Desktop.
Any and All Puzzle
using static System.Console;
using System.Collections.Generic;
using System.Linq;
namespace AnyAndAll
{
public class Program
{
public static void Main(string[] args)
{
var sequence = GetSpecialSequence();
// Prints "True"
WriteLine(sequence.All(b => b == true));
// Prints "False"
WriteLine(sequence.Any(b => b == true));
}
private static IEnumerable<bool> GetSpecialSequence()
{
// Puzzle: What should this implementation be?
return null;
}
}
}
@pawanprakashpal
Copy link

Your function can return a simple empty instance.

return new List∆bool∆();

@pavel-yermalovich
Copy link

pavel-yermalovich commented Jul 28, 2016

private static IEnumerable<bool> GetSpecialSequence() => Enumerable.Empty<bool>();

@LesRamer
Copy link

LesRamer commented Dec 2, 2016

My buddy once said: 'All of my purses are coach purses.' His statement was vacuously true because he owns no purses at all (or at least that's what he wants me to believe.)

var ownedPurses = Enumerable.Empty<Purse>();
Func<Purse, bool> isCoachPurse = purse => purse is CoachPurse;

Console.WriteLine(ownedPurses.All(isCoachPurse)); // all of the purses ARE coach purses
Console.WriteLine(!ownedPurses.Any(purse => !isCoachPurse(purse))); // none of the purses are NOT coach purses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment