diff Assets/Application/Scripts/Test/FunctorTest.cs @ 13:e297afe0889d default tip

Add Prefab.
author Kazuma Takeda
date Tue, 07 Feb 2017 20:49:26 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Assets/Application/Scripts/Test/FunctorTest.cs	Tue Feb 07 20:49:26 2017 +0900
@@ -0,0 +1,37 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class FunctorTest : MonoBehaviour {
+
+	private List<int> list = new List<int>(){ 1, 2, 3, 4, 5 };
+	private List<string> slist = new List<string>() { "Hello", "World" };
+
+	private void Start () {
+		System.Func<int, int> f =  (int arg) => {
+			return arg * 2;
+		};
+
+		list = Functor.map (f, list);
+
+		 print (getString (list));
+
+		System.Func<string, string> fs =  (string arg) => {
+			return arg + "(ΦωΦ)";
+		};
+
+		slist = Functor.map (fs, slist);
+
+		print (getString(slist));
+	}
+		
+	private string getString<T> (List<T> l) {
+		string s = "[";
+		foreach (T n in l) {
+			s += n + ", ";
+		}
+		s = s.Remove (s.Length - 1);
+		s += "]";
+		return s;
+	}
+}