using System.Collections.Generic; using System.Linq; using UnityEngine; using Monad; public class TestMonad : MonoBehaviour { // Start is called before the first frame update void Start() { var oddResult = FindOdd(new[] {1, 1, 3, 5, 7, 9, 7}); if (oddResult.HasValue()) { Debug.Log("-->Odd Index: " + oddResult.Value()); } else { Debug.Log("-->Not found"); } } private Option FindOdd(IEnumerable lst) { var indexList = lst.Select((item, index) => new {Item = item, Index = index}) .Where(pair => pair.Item % 2 == 0) .Select(pair => pair.Index); return !indexList.Any() ? Option.Nothing() : Option.Return(indexList.First); } }