Last active
August 29, 2015 13:57
-
-
Save ormaaj/9695693 to your computer and use it in GitHub Desktop.
Mutable LINQ object wrapper
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Program { | |
public class NodeThing<T> { | |
public T Value; | |
public NodeThing() { } | |
public NodeThing(T value) { | |
this.Value = value; | |
} | |
public static implicit operator NodeThing<T>(T x) { | |
return new NodeThing<T>(x); | |
} | |
public static explicit operator T(NodeThing<T> x) { | |
return x.Value; | |
} | |
} | |
class Program { | |
static void Main(string[] args) { | |
var fun = ((Func<IList<NodeThing<int>>, IEnumerable<int>>)(x => x.Select((n, idx) => idx < x.Count - 1 ? x[idx + 1].Value = n.Value * 2 : n.Value))); | |
Console.WriteLine(string.Join(", ", fun(new List<NodeThing<int>> { 1, 2, 3, 4, 5 }))); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment