Exemplo n.º 1
0
 protected override Maybe <Type> DefaultTypeFor(Type type)
 {
     return
         (new Maybe <Type>(
              _container.Apply(c => c.Registrations.FirstOrDefault(r => r.RegisteredType == type))
              .Do(r => r.MappedToType)));
 }
Exemplo n.º 2
0
        public void Apply_EmptyMaybeReturnsEmptyMaybe()
        {
            Maybe <string> str = new Maybe <string>(null);

            Maybe <object> obj = str.Apply(x => (Object)x);

            Assert.IsNotNull(obj);
            Assert.IsFalse(obj.HasValue);
        }
Exemplo n.º 3
0
        public void Apply_NullFunctionReturnsEmptyMaybe()
        {
            Maybe <string> str = new Maybe <string>("abc");

            Maybe <object> obj = str.Apply <object>(null);

            Assert.IsNotNull(obj);
            Assert.IsFalse(obj.HasValue);
        }
Exemplo n.º 4
0
        public void Apply_EmptyMaybeReturnsEmptyMaybe()
        {
            Maybe<string> str = new Maybe<string>(null);

            Maybe<object> obj = str.Apply(x=>(Object)x);

            Assert.IsNotNull(obj);
            Assert.IsFalse(obj.HasValue);
        }
Exemplo n.º 5
0
        public void Apply_NullFunctionReturnsEmptyMaybe()
        {
            Maybe<string> str = new Maybe<string>("abc");

            Maybe<object> obj = str.Apply<object>(null);

            Assert.IsNotNull(obj);
            Assert.IsFalse(obj.HasValue);
        }
Exemplo n.º 6
0
        public void Apply_NonEmptyMaybeReturnsNonEmptyMaybe()
        {
            Maybe <string> str = new Maybe <string>("abc");

            Maybe <string> obj = str.Apply(x => x + "123");

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj.HasValue);
            Assert.AreEqual("abc123", obj.Value);
        }
Exemplo n.º 7
0
        public void Apply_NonEmptyMaybeReturnsNonEmptyMaybe()
        {
            Maybe<string> str = new Maybe<string>("abc");

            Maybe<string> obj = str.Apply(x => x + "123");

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj.HasValue);
            Assert.AreEqual("abc123", obj.Value);
        }
        private Maybe <TOutput> ProcessResult(Maybe <TInput> item)
        {
            if (item.IsEmpty)
            {             // that was the last one !
                m_receivedLast = true;
                LogConsumer("Received last item");
                return(Maybe.Nothing <TOutput>());
            }

            LogConsumer("Applying transform on item");
            return(Maybe.Apply <TInput, TOutput>(item, m_transform));
        }
Exemplo n.º 9
0
            public bool Third_law(int y)
            {
                // u <*> pure y = pure ($ y) <*> u
                // u <*> (pure y) = (pure ($ y)) <*> u
                // apply u (pure y) = apply (pure ($ y)) u
                // apply u (pure y) = apply (pure (\x -> x $ y)) u
                // apply u (pure y) = apply (pure (\x -> ($) x y)) u
                // apply u (pure y) = apply (pure (\x -> x y)) u

                Maybe <Func <int, int> > u = Maybe <Func <int, int> > .Just(i => i + 1);

                var left = u.Apply(Maybe.Pure(y));

                //                           \x -> x y
                Func <Func <int, int>, int> f = h => h(y);
                var right = Maybe.Pure(f).Apply(u);

                return(left.Equals(right));
            }
        private string ExecuteInternal(Maybe<string> pipeIn)
        {
            StartProcess();
            pipeIn.Apply(WriteToStandardIn);
            var output = GetOutputAndWait();
            CheckExitCode();

            return output;
        }
Exemplo n.º 11
0
            public bool Invoking_applied_nothing_function_with_just_a_value_returns_nothing(int i)
            {
                Func <Maybe <int>, Maybe <int> > appliedNothingFunc = NothingFunc.Apply();

                return(appliedNothingFunc(Maybe <int> .Just(i)).Equals(Maybe <int> .Nothing));
            }
Exemplo n.º 12
0
            public bool Invoking_applied_elevated_function_with_just_a_value_returns_just_function_result(int i)
            {
                Func <Maybe <int>, Maybe <int> > appliedElevatedFunc = ElevatedFunc.Apply();

                return(appliedElevatedFunc(Maybe <int> .Just(i)).Equals(Maybe <int> .Just(IntDivBy2(i))));
            }
Exemplo n.º 13
0
        public void Apply()
        {
            Func <int, string> func = value => value.ToString();

            Assert.Equal("5", Some5.Apply(func.ToSome()).Value);
        }
Exemplo n.º 14
0
 public static Maybe <R> Apply <A, R>(this Maybe <Func <A, R> > fn, Maybe <A> @this) => @this.Apply(fn);