Created
August 10, 2011 17:03
-
-
Save jrwren/1137431 to your computer and use it in GitHub Desktop.
unfold a datareader.
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
public virtual List<CreditUnion> ExecuteF(Func<System.Data.IDataReader, CreditUnion> map) | |
{ | |
var command = _database.GetStoredProcCommand("GETALLA2A");//ENTLIB? | |
_database.AddInParameter(command, "mode", System.Data.DbType.String, "M"); | |
var list = new List<CreditUnion>(); | |
using (var reader = _database.ExecuteReader(command)) | |
//turn Read into a generator... e.i unfold | |
// :) http://jrwren.wrenfam.com/blog/2008/12/26/functional-functions/ | |
// Read just isn't functional so we use "let" and TakeWhile. | |
return | |
SRTSolutions.Elevate.Seq.Unfold(reader, r => r.Read() ? Option.Some(r) : Option<System.Data.IDataReader>.None) | |
.Select(r => map(r)) | |
.ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment