Last active
August 29, 2015 14:13
-
-
Save eral/d2ad96c34466f7d77b4d to your computer and use it in GitHub Desktop.
Cancelable LINQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by ERAL | |
// This is free and unencumbered software released into the public domain. | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class CancelableLinq { | |
[MenuItem("Test/Cancelable LINQ")] | |
public static void Test() { | |
var enumerable = CreateEnumerable(); | |
var progressDelta = 1.0f / enumerable.Count(); | |
var logs = enumerable.TakeWhile((x,i)=>!EditorUtility.DisplayCancelableProgressBar("Cancelable LINQ", x.ToString(), i * progressDelta)) | |
.Select(x=>string.Format("{0}^2 == {1}", x, x * x)) | |
.ToArray(); | |
EditorUtility.ClearProgressBar(); | |
DisplayLogs(logs); | |
} | |
private static IEnumerable<int> CreateEnumerable() { | |
return Enumerable.Range(0, 1000); | |
} | |
private static void DisplayLogs(string[] logs) { | |
foreach (var log in logs) { | |
Debug.Log(log); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment