コード例 #1
0
    //
    // Produza-se um IEnumerable em que cada elemento resulta de
    // aplicar 'func' a um elemento de 'source'.
    //
    // Implementação 'lazy' de algoritmo de Map, que vai calculando os resultados
    // à medida que forem sendo precisos.
    //
    // Usa a palavra-chave yield, levando a que o compilador de C# gere automaticamente
    // uma implementação equivalente à apresentada no passo anterior ('LazyMap').
    //

    #region LazyMapWithYield

    public static IEnumerable <U> YieldedMap <T, U>(this IEnumerable <T> source, Func1 <T, U> func)
    {
        foreach (T obj in source)
        {
            yield return(func(obj));
        }
    }
コード例 #2
0
    public HistoryView(UserData data, Func1 setButtons, Func2 changeView, Func3 makeRequest)
    {
        //init user data
        userData = data;

        //init widgets
        delete = new Button("Delete history");
        vBox   = new VBox(false, 20);

        //populate items list
        items = new List <HistoryItem>();
        foreach (UserData.History h in userData.history)
        {
            items.Add(new HistoryItem(h.url, h.time.ToString(), h.title));
        }

        //init and add items to the view
        for (int i = items.Count - 1; i >= 0; i--)
        {
            vBox.PackStart(items[i], false, false, 0);
            items[i].gotoUrl.Clicked += (obj, args) => gotoHistory(changeView, makeRequest, ((HistoryItem)((Button)obj).Parent.Parent).url);
        }

        //add main event handlers
        delete.Clicked += (obj, args) => deleteHistory(setButtons);

        //finish layout
        vBox.PackStart(delete, false, false, 0);
        this.Add(vBox);
    }
コード例 #3
0
    //
    // Produza-se um IEnumerable em que cada elemento resulta de
    // aplicar 'func' a um elemento de 'source'.
    //
    // Implementação 'lazy' de algoritmo de Map, que vai calculando os resultados
    // à medida que forem sendo precisos.
    //
    // Usa a palavra-chave yield, levando a que o compilador de C# gere automaticamente
    // uma implementação equivalente à apresentada no passo anterior ('LazyMap').
    //

    #region LazyMapWithYield

    public static IEnumerable YieldedMap(this IEnumerable source, Func1 func)
    {
        foreach (Object obj in source)
        {
            yield return(func(obj));
        }
    }
コード例 #4
0
        private async void doPreload(String url, Func0 onSuccess, Func1 onError)
        {
            try
            {
                await media.getCachedObjectAsync(new Uri(base_url, url.TrimStart('/')));

                if (!runtime.IsRunning)
                {
                    return;
                }

                using (var ctx = new FlowRuntime.DeferredContext(runtime))
                {
                    onSuccess();
                }
            }
            catch (Exception e)
            {
                if (!runtime.IsRunning)
                {
                    return;
                }

                using (var ctx = new FlowRuntime.DeferredContext(runtime))
                {
                    onError(e.ToString());
                }
            }
        }
コード例 #5
0
        public override Object loadSound(String url, Func1 onfail, Func0 onok)
        {
            var obj = new Sound(this, new Uri(base_url, url));

            obj.startLoad(onfail, onok);
            return(obj);
        }
コード例 #6
0
        static void Main()
        {
            Func1       ToDigitArray = IntToNumbers;
            Func2 <int> PrintArray   = PrintIntArray;

            do
            {
                Console.Clear();

                int   randomNumber = rnd.Next(10000, 100000);
                int[] randomArray  = new int[10];
                for (int i = 0; i < randomArray.Length; ++i)
                {
                    randomArray[i] = rnd.Next(10, 100);
                }

                Console.WriteLine("Random number: " + randomNumber);

                Console.WriteLine("Number to digits: ");
                PrintArray(ToDigitArray(randomNumber));
                Console.WriteLine("Print array: ");
                PrintArray(randomArray);
                Console.WriteLine("ToDigitArray.Method: " + ToDigitArray.Method);
                Console.WriteLine("ToDigitArray.Target: " + ToDigitArray.Target);
                Console.WriteLine("PrintArray.Method: " + PrintArray.Method);
                Console.WriteLine("PrintArray.Target: " + PrintArray.Target);

                Console.WriteLine("Press Esc to exit. Press any other key to continue.");
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
コード例 #7
0
    public FavoritesView(UserData data, Func1 updateStatus, Func2 changeView, Func3 makeRequest)
    {
        //init user data
        userData = data;

        //init widgets
        items = new List <FavoriteItem>();
        vBox  = new VBox(false, 20);

        //populate item list
        foreach (UserData.Favorite f in userData.favorites)
        {
            items.Add(new FavoriteItem(f.url, f.name));
        }

        //init and add items to the view
        for (int i = 0; i < items.Count; i++)
        {
            vBox.PackStart(items[i], false, false, 0);
            items[i].save.Clicked    += (obj, args) => updateName((FavoriteItem)((Button)obj).Parent, updateStatus);
            items[i].gotoUrl.Clicked += (obj, args) => gotoFav(changeView, makeRequest, ((FavoriteItem)((Button)obj).Parent).urlEntry.Text);
        }

        //finalise
        this.Add(vBox);
    }
コード例 #8
0
 public Scoped1(T4 t4, Scoped2 scoped2, Func1 func1, Single1 single1)
 {
     T4      = t4;
     Scoped2 = scoped2;
     Func1   = func1;
     Single1 = single1;
 }
コード例 #9
0
    void IInvocation.invoke()
    {
        if (avalabilityCheck() == false)
        {
            return;
        }

        if (_hasReturnValue)
        {
            R obj = default(R);
            switch (_argCount)
            {
            case 0:
                Func <R> f = (Func <R>)_func;
                obj = f();
                break;

            case 1:
                Func1 <R, Arg1> f1 = (Func1 <R, Arg1>)_func;
                obj = f1((Arg1)_argList[0]);
                break;

            case 2:
                Func2 <R, Arg1, Arg2> f2 = (Func2 <R, Arg1, Arg2>)_func;
                obj = f2((Arg1)_argList[0], (Arg2)_argList[1]);
                break;

            default:
                Log.infoError("Function with " + _argCount + " arguments is not supported!");
                break;
            }

            _returnValue = (object)obj;
        }
        else
        {
            switch (_argCount)
            {
            case 0:
                VFunc vf = (VFunc)_func;
                vf();
                break;

            case 1:
                VFunc1 <Arg1> vf1 = (VFunc1 <Arg1>)_func;
                vf1((Arg1)_argList[0]);
                break;

            case 2:
                VFunc2 <Arg1, Arg2> vf2 = (VFunc2 <Arg1, Arg2>)_func;
                vf2((Arg1)_argList[0], (Arg2)_argList[1]);
                break;

            default:
                Log.infoError("Function with " + _argCount + " arguments is not supported!");
                break;
            }
        }
    }
コード例 #10
0
 public void updateName(FavoriteItem f, Func1 updateStatus)
 {
     if (f.nameEntry.Text != "")
     {
         updateStatus("Saved");
         userData.changeFavoriteName(f.nameEntry.Text, f.urlEntry.Text);
     }
 }
コード例 #11
0
 public static IEnumerable Map(this IEnumerable objs, Func1 mapper)
 {
     foreach (Object obj in objs)
     {
         Console.WriteLine(":: Generating one more item ::");
         yield return(mapper(obj));
     }
 }
コード例 #12
0
ファイル: Native.cs プロジェクト: yibit/flow9
 public Object iter(Object[] arr, Func1 clos)
 {
     for (int i = 0; i < arr.Length; i++)
     {
         clos(arr[i]);
     }
     return(null);
 }
コード例 #13
0
 public static IEnumerable <U> Map <T, U>(this IEnumerable <T> objs, Func1 <T, U> mapper)
 {
     foreach (T obj in objs)
     {
         Console.WriteLine(":: Generating one more item ::");
         yield return(mapper(obj));
     }
 }
コード例 #14
0
 public void deleteHistory(Func1 setButtons)
 {
     userData.deleteHistory();
     for (int i = items.Count - 1; i >= 0; i--)
     {
         vBox.Remove(items[i]);
     }
     setButtons();
 }
コード例 #15
0
        public override async Task <Object> sendHttpRequestWithAttachments(String url, Object[] headers, Object[] param, Object[] files, Func1 onData, Func1 onError)
        {
            HttpRequestMessage message = await composeHttpRequest(url, false, headers, param, files);

            Func1 onStatus = (object a) => { return(null); };

            submitRequest(message, onData, onError, onStatus);
            return(null);
        }
コード例 #16
0
ファイル: Native.cs プロジェクト: yibit/flow9
 public Object[] map(Object[] arr, Func1 clos)
 {
     Object[] rv = new Object[arr.Length];
     for (int i = 0; i < arr.Length; i++)
     {
         rv[i] = clos(arr[i]);
     }
     return(rv);
 }
コード例 #17
0
    //
    // Produza-se um IEnumerable em que cada elemento resulta de
    // aplicar 'func' a um elemento de 'source'.
    //
    // Implementação 'eager', que usa uma colecção para guardar o resultado
    // do processamento de toda a sequência de entrada.
    //
    public static IEnumerable EagerMap(this IEnumerable source, Func1 func)
    {
        IList res = new ArrayList();

        foreach (Object obj in source)
        {
            res.Add(func(obj));
        }
        return(res);
    }
コード例 #18
0
    static public Operation DoFuncOnMainThread <R, Arg1>(Func1 <R, Arg1> func, Arg1 arg, long delay = 0, VFunc1 <R> callback = null)
    {
        object[] args = { arg };
        Invocation <R, Arg1, Null> inv   = new Invocation <R, Arg1, Null> (func, 1, args, true);
        Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1, null);
        Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv);

        MainThread.Instance.addExcutable(operation);
        return(operation);
    }
コード例 #19
0
    //
    // Produza-se um IEnumerable em que cada elemento resulta de
    // aplicar 'func' a um elemento de 'source'.
    //
    // Implementação 'eager', que usa uma colecção para guardar o resultado
    // do processamento de toda a sequência de entrada.
    //
    public static IEnumerable <U> EagerMap <T, U>(this IEnumerable <T> source, Func1 <T, U> mapper)
    {
        IList <U> res = new List <U>();

        foreach (T obj in source)
        {
            res.Add(mapper(obj));
        }
        return(res);
    }
コード例 #20
0
    //
    // Produza-se um IEnumerable em que cada elemento resulta de
    // aplicar 'func' a um elemento de 'source'.
    //
    // Implementação 'eager', que usa uma colecção para guardar o resultado
    // do processamento de toda a sequência de entrada.
    //
    public static IEnumerable EagerMap(this IEnumerable source, Func1 mapper)
    {
        IList res = new List <Object>();

        foreach (Object obj in source)
        {
            res.Add(mapper(obj));
        }
        return(res);
    }
コード例 #21
0
    static public Operation DoFuncOnThread <R, Arg>(LoopThread loopThrad, Func1 <R, Arg> func, Arg arg, VFunc1 <R> callback = null, bool callbackOnMainThread = true, long delay = 0)
    {
        object[] args = { arg };
        Invocation <R, Arg, Null>  inv   = new Invocation <R, Arg, Null> (func, 1, args, true);
        Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1);
        Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv, callbackOnMainThread);

        loopThrad.addExecution(operation);
        return(operation);
    }
コード例 #22
0
ファイル: Native.cs プロジェクト: yibit/flow9
 public bool exists(Object[] arr, Func1 test)
 {
     for (int i = 0; i < arr.Length; i++)
     {
         if ((bool)test(arr[i]))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #23
0
        static void Main(string[] args)
        {
            Func1 <Cat>    cat    = () => new Cat();
            Func1 <Animal> animal = cat;

            Action1 <Animal> act1 = (ani) => { Console.WriteLine(ani); };
            Action1 <Cat>    cat1 = act1;

            Console.WriteLine(animal());
            cat1(new Cat());
        }
コード例 #24
0
        public JsonTypeMemberEntry(string jsonName, FieldInfo fieldInfo)
        {
            IsEscapingRequired = JsonWriter.IsEscapingRequired(jsonName);
            MemberType         = fieldInfo.FieldType;

            ReadValue = Accelerator.CreateInstanceGetter(fieldInfo);

            if (!fieldInfo.IsInitOnly)
            {
                WriteValue = Accelerator.CreateInstanceSetter(fieldInfo);
            }
        }
コード例 #25
0
        public void TestCreateInstanceGetter1()
        {
            string n        = nameof(ClassWithInstanceFields.InstanceValueField);
            Func1  getValue = typeof(ClassWithInstanceFields).CreateInstanceGetter(n);

            var e = new ClassWithInstanceFields();

            Assert.AreEqual(0, e.InstanceValueField);
            e.InstanceValueField = 123;
            Assert.AreEqual(123, getValue(e));
            e.InstanceValueField = 0;
            Assert.AreEqual(0, getValue(e));
        }
コード例 #26
0
        public void TestCreateInstanceGetter2()
        {
            string n        = nameof(ClassWithInstanceFields.InstanceTextField);
            Func1  getValue = typeof(ClassWithInstanceFields).CreateInstanceGetter(n);

            var e = new ClassWithInstanceFields();

            Assert.AreEqual(null, e.InstanceTextField);
            e.InstanceTextField = "ABC";
            Assert.AreEqual("ABC", getValue(e));
            e.InstanceTextField = null;
            Assert.AreEqual(null, getValue(e));
        }
コード例 #27
0
        public void TestCreateInstanceGetter3()
        {
            string n        = nameof(ClassWithInstanceFields.InstanceEnumField);
            Func1  getValue = typeof(ClassWithInstanceFields).CreateInstanceGetter(n);

            var e = new ClassWithInstanceFields();

            Assert.AreEqual(EnumForTest.None, e.InstanceEnumField);
            e.InstanceEnumField = EnumForTest.Example;
            Assert.AreEqual(EnumForTest.Example, getValue(e));
            e.InstanceEnumField = EnumForTest.None;
            Assert.AreEqual(EnumForTest.None, getValue(e));
        }
コード例 #28
0
ファイル: Native.cs プロジェクト: yibit/flow9
            void readStructIndex(Func1 fixups)
            {
                int offset = readInt32();

                if (error || offset < char_idx || offset >= input_size)
                {
                    error = true;
                    return;
                }

                int old_pos = char_idx;

                char_idx = offset;

                int isize = readArraySize();

                structPrototype = new Struct[isize];
                structSize      = new int[isize];
                structFixups    = new Func1[isize];

                for (int i = 0; i < isize; i++)
                {
                    if (readArraySize() != 2)
                    {
                        error = true;
                        return;
                    }

                    int    fcount = readInteger();
                    string name   = readString();

                    structPrototype[i] = parent.runtime.findStructPrototype(name);
                    structSize[i]      = fcount;

                    if (fixups != null)
                    {
                        Struct   tmp  = (Struct)fixups(name);
                        object[] data = tmp.getFields();

                        // Some(fixup_cb)
                        if (data.Length > 0)
                        {
                            structFixups[i] = (Func1)data[0];
                        }
                    }
                }

                char_idx   = old_pos;
                input_size = offset;
            }
コード例 #29
0
        public void TestCreateFunction1c()
        {
            string     n            = nameof(ExampleClass2.AppendTextAndGet);
            MethodInfo m            = typeof(ExampleClass2).GetMethod(n, Type.EmptyTypes);
            Func1      appendAndGet = Accelerator.CreateFunction1(m);

            var o = new ExampleClass2();

            Assert.AreEqual(null, o.Text);
            o.Text = "ABC";
            Assert.AreEqual("ABCtext", o.AppendTextAndGet());
            Assert.AreEqual("ABCtext", o.Text);
            Assert.AreEqual("ABCtexttext", appendAndGet(o));
            Assert.AreEqual("ABCtexttext", o.Text);
        }
コード例 #30
0
        public JsonTypeMemberEntry(string jsonName, Type propertyType, MethodInfo getMethod, MethodInfo setMethod)
        {
            IsEscapingRequired = JsonWriter.IsEscapingRequired(jsonName);
            MemberType         = propertyType;

            if (getMethod != null)
            {
                ReadValue = Accelerator.CreateFunction1(getMethod);
            }

            if (setMethod != null)
            {
                WriteValue = Accelerator.CreateAction2(setMethod);
            }
        }
コード例 #31
0
ファイル: NP.cs プロジェクト: PisalPrasad123/CrystalBox
 public static double[] Broadcast(Func1 f, double[] x)
 {
     double[] ret = new double[x.Length];
     for (int i = 0; i < x.Length; i++)
     {
         ret[i] = f(x[i]);
     }
     return ret;
 }
コード例 #32
0
ファイル: GlTest.cs プロジェクト: mortezabarzkar/SharpNative
 static  extern      void glutDisplayFunc(Func1 g);
コード例 #33
0
ファイル: GlTest.cs プロジェクト: mortezabarzkar/SharpNative
 static  extern      void glutIdleFunc(Func1 g);
コード例 #34
0
 public void HandledBy(Func1 handler) { SetHandledBy(handler, 1, HandlerContextParam.None); }