Example #1
0
 /// <summary>
 /// Applies an action to a functor and returns it.
 /// The action is presumable mutating.
 /// </summary>
 /// <typeparam name="TSource">The source type of the functor.</typeparam>
 /// <param name="f">The functor.</param>
 /// <param name="a">The action to apply to the values in the functor.</param>
 public static IFunctor <TSource> Map <TSource>(this IFunctor <TSource> f, Action <TSource> a)
 => f.Map(x => { a(x); return(x); });
Example #2
0
 /// <summary>
 /// Equivalent to <see cref="IFunctor{TSource}.Map{TResult}(Func{TSource, TResult})"/>. The functor-type is preserved, but checking for a concrete type is the responsibility of the caller.
 /// Offers LINQ query support with one <c>from</c>-clause.
 /// </summary>
 /// <typeparam name="TSource">The type of the source's value.</typeparam>
 /// <typeparam name="TResult">The type of the result's value.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="f">The function to apply.</param>
 public static IFunctor <TResult> Select <TSource, TResult>(this IFunctor <TSource> source, Func <TSource, TResult> f)
 => source.Map(f);
Example #3
0
 /// <summary>
 /// Erases the contents of a functor.
 /// </summary>
 /// <typeparam name="TSource">The source type of the functor.</typeparam>
 /// <param name="f">The functor.</param>
 public static IFunctor <Unit> Void <TSource>(this IFunctor <TSource> f) => f.Map(x => new Unit());