public RowParserResult <T> Parse(TRow row) { try { return(_parser(row)); } catch (Exception ex) { return(RowParserResult.Failed <T>(ex)); } }
private static RowParser <T, IDataRecord> Simple <T>(int col, Func <IDataRecord, T> f) { return(new RowParser <T, IDataRecord>(row => { if (row.IsDBNull(col)) { return RowParserResult.Failed <T>(UnexpectedNullFieldException.UnexpectedNull); } return RowParserResult.Successful(f(row)); })); }
public static RowParser <IMaybe <T>, IDataRecord> Optional <T>(RowParser <T, IDataRecord> other) { return(new RowParser <IMaybe <T>, IDataRecord>(row => { return other.Parse(row).Map(Maybe.Just).Recover(ex => { if (ex == UnexpectedNullFieldException.UnexpectedNull) { return RowParserResult.Successful(Maybe.Nothing <T>()); } return RowParserResult.Failed <IMaybe <T> >(ex); }); })); }
public static RowParser <T, IDataRecord> Named <T>(string name, Func <int, RowParser <T, IDataRecord> > byIndexParser) { return(new RowParser <int, IDataRecord>(row => RowParserResult.Successful(row.GetOrdinal(name))) .FlatMap(byIndexParser)); }