Skip to content

Instantly share code, notes, and snippets.

@darrencauthon
Created November 11, 2010 12:22
Show Gist options
  • Save darrencauthon/672410 to your computer and use it in GitHub Desktop.
Save darrencauthon/672410 to your computer and use it in GitHub Desktop.
To Use a Tuple or Not? Not, I say.
void Main()
{
var people = new []{
new Person() { Id = 1, FirstName = "Darren", LastName = "Cauthon", IsAFanOfAynRand = true, IsACoolPerson = true},
new Person() { Id = 2, FirstName = "Caleb", LastName = "Cauthon", IsAFanOfAynRand = true, IsACoolPerson = false},
new Person() { Id = 3, FirstName = "Evan", LastName = "Cauthon", IsAFanOfAynRand = false, IsACoolPerson = true},
};
var unreadable = new UnreadableCoolAynRandFanRetriever(people);
var readable = new ReadableCoolAynRandFanRetriever(people);
Tuple<int, string> howInTheHeckCanAnybodyReadThis = unreadable.GetTheCoolFansOfAynRand().First();
CoolFanOfAynRand anybodyWouldKnowWhatThisIs = readable.GetTheCoolFansOfAynRand().First();
}
public class UnreadableCoolAynRandFanRetriever{
private IEnumerable<Person> people;
public UnreadableCoolAynRandFanRetriever(IEnumerable<Person> people){
this.people = people;
}
public IEnumerable<Tuple<int, string>> GetTheCoolFansOfAynRand() {
return people
.Where(p=>p.IsACoolPerson)
.Where(p=>p.IsAFanOfAynRand)
.Select(p=>Tuple.Create<int, string>(p.Id, p.FirstName + " " + p.LastName));
}
}
public class ReadableCoolAynRandFanRetriever {
private IEnumerable<Person> people;
public ReadableCoolAynRandFanRetriever(IEnumerable<Person> people){
this.people = people;
}
public IEnumerable<CoolFanOfAynRand> GetTheCoolFansOfAynRand() {
return people
.Where(p=>p.IsACoolPerson)
.Where(p=>p.IsAFanOfAynRand)
.Select(p=>new CoolFanOfAynRand{Id = p.Id, Name = p.FirstName + " " + p.LastName});
}
}
public class CoolFanOfAynRand {
public int Id { get; set; }
public string Name { get; set; }
}
public class Person {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsACoolPerson { get; set; }
public bool IsAFanOfAynRand { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment