main
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace jive
 6{
 7  static public class MappingExtensions
 8  {
 9    static public Output map_using<Input, Output>(this Input item, Converter<Input, Output> conversion)
10    {
11      return conversion(item);
12    }
13
14    static public Output map_using<Input, Output>(this Input item, Mapper<Input, Output> mapper)
15    {
16      return map_using(item, x => mapper.map_from(x));
17    }
18
19    static public Output map_using<Input, Output>(this Input item, Mapper mapper)
20    {
21      return map_using(item, x => mapper.map_from<Input, Output>(x));
22    }
23
24    static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
25        Converter<Input, Output> mapper)
26    {
27      return null == items ? Enumerable.Empty<Output>() : items.Select(x => mapper(x));
28    }
29
30    static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
31        Mapper<Input, Output> mapper)
32    {
33      return map_all_using(items, x => mapper.map_from(x));
34    }
35
36    static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
37        Mapper mapper)
38    {
39      return map_all_using(items, x => mapper.map_from<Input, Output>(x));
40    }
41
42    static public Mapper<Left, Right> then<Left, Middle, Right>(this Mapper<Left, Middle> left,
43        Mapper<Middle, Right> right)
44    {
45      return new ChainedMapper<Left, Middle, Right>(left, right);
46    }
47  }
48}