Skip to content

Instantly share code, notes, and snippets.

@jrwren
Created August 10, 2011 17:03
Show Gist options
  • Save jrwren/1137431 to your computer and use it in GitHub Desktop.
Save jrwren/1137431 to your computer and use it in GitHub Desktop.
unfold a datareader.
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