コード例 #1
0
        /// <summary>
        /// (&lt;$)
        /// <para>a = TResult, b = TSource</para>
        /// <para>Create a new f a from an f b by replacing all of the values in
        /// the f b by a given value of type a.</para>
        /// </summary>
        public static Mayhap <TResult> ReplaceWith <TSource, TResult>(
            TResult value,
            Mayhap <TSource> mayhap)
            where TResult : notnull
        {
            // (<$) :: Functor f => a -> f b -> f a | infixl 4 |
            //
            // (<$) :: a -> f b -> f a
            // (<$) =  fmap . const
            //
            // Replace all locations in the input with the same value. The
            // default definition is fmap . const, but this may be overridden
            // with a more efficient version.
            //
            // Examples:
            //   "xxx" <$ Nothing == Nothing
            //   "xxx" <$ Just 1  == Just "xxx"

#if STRICT_HASKELL
            return(Map(__const, mayhap));

            // NB: this is just (_ => value).
            TResult __const(TSource x) => Thunks <TResult, TSource> .Const1(value, x);
#else
            return(mayhap.Select(_ => value));
#endif
        }
コード例 #2
0
            // First law: the identity map is a fixed point for Select.
            //   fmap id  ==  id
            public static bool IdentityRule <T>(Mayhap <T> mayhap)
            {
#if STRICT_HASKELL
                return(Map(Thunks <T> .Ident, mayhap)
                       == Thunks <Mayhap <T> > .Ident(mayhap));
#else
                return(mayhap.Select(Thunks <T> .Ident)
                       == Thunks <Mayhap <T> > .Ident(mayhap));
#endif
            }
コード例 #3
0
 public static void Test10(ref Thunks obj)
 {
     obj = new Thunks();
 }