You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

26 lines
763 B

  1. using System;
  2. using System.Collections.Generic;
  3. public static class ListApplyAndFunction
  4. {
  5. public static List<TResult> Apply<TResult, TInput>(this IEnumerable<TInput> input, ListApplyAndFunction.Function<TResult, TInput> function, bool discardNulls = false)
  6. {
  7. List<TResult> list = new List<TResult>();
  8. foreach (TInput arg in input)
  9. {
  10. TResult tresult = function(arg);
  11. if (!discardNulls || tresult != null)
  12. {
  13. list.Add(tresult);
  14. }
  15. }
  16. return list;
  17. }
  18. public delegate TResult Function<out TResult, TArg1>(TArg1 arg1);
  19. public delegate TResult Function<out TResult, TArg1, TArg2>(TArg1 arg1, TArg2 arg2);
  20. public delegate TResult Function<out TResult, TArg1, TArg2, TArg3>(TArg1 arg1, TArg2 arg2, TArg3 arg3);
  21. }