Last active
April 20, 2016 17:44
-
-
Save IanWold/a1041c199f81a36e3c9f847b8192e0b5 to your computer and use it in GitHub Desktop.
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
//in Parse.cs | |
public static Parser<U> EnumerateInput<T, U>(IEnumerable<T> input, Func<T, Parser<U>> parser) | |
{ | |
if (input == null) throw new ArgumentNullException("input"); | |
if (parser == null) throw new ArgumentNullException("parser"); | |
return EnumerateInput(input.ToArray(), parser); | |
} | |
public static Parser<U> EnumerateInput<T, U>(T[] input, Func<T, Parser<U>> parser) | |
{ | |
if (input == null || input.Length == 0) throw new ArgumentNullException("input"); | |
if (parser == null) throw new ArgumentNullException("parser"); | |
return i => | |
{ | |
var res = (IResult<U>)(new Result<U>(null, null, null)); | |
foreach (var inp in input) | |
{ | |
res = parser(inp)(i); | |
if (res.WasSuccessful) return res; | |
} | |
return res; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment