view 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 source

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;
	}
}