Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/9695693 to your computer and use it in GitHub Desktop.
Save ormaaj/9695693 to your computer and use it in GitHub Desktop.
Mutable LINQ object wrapper
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