Created
November 11, 2010 12:22
-
-
Save darrencauthon/672410 to your computer and use it in GitHub Desktop.
To Use a Tuple or Not? Not, I say.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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