-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Interface007 edited this page Jan 29, 2015
·
1 revision
So you might wonder what this project is about. Well I simply saw a talk about using F# to hable processing of items in a list with "per item error handling" in a LINQ-linke query (the items were "tagged unions" or "sum type", where one instance can be of one of two strong types). I did wonder whether this would be possible in C#, so I simply tried it for fun - the result is this little project.
Example from the unit-tests:
var logger = new ExceptionLogger();
var counter = new ExecutionCounter();
var res1 = new[] { "1", "12", "123", "1234", null, "12345" }
.WithAction<string, int>(counter.Action2) // here we wrap each value into a function
.WithAction<string, int>(counter.Action3) // this will add another layer around the values
.Skip(1) // since the function execution is deferred, we will only get 5 invocations of counter.Action3
.Try(Calculate) // here the value is calculated while calling the two actions defined above
.WhenIs(logger.HandleException) // we will execute this for each exception-item
.ToArray(); // this will enumerate all items
Assert.AreEqual(5, res1.Count()); // we should have 5 return values
Assert.AreEqual(5, counter.Count); // we have only 5 executions of the calculation
Assert.AreEqual(2, logger.List.Count()); // out list of logs contains two exceptions
Assert.AreEqual(100, (int)res1[1]); // check for a successfull result