public void GenFromPropertyExpression() { var fn = Lens.Of((Person x) => x.FirstName); var ln = Lens.Of((Person x) => x.LastName); var ct = Lens.Of((Address x) => x.City); var address = new Address("123 Fake Street", "Anytown"); var person = new Person("John", "Doe", address); Assert.AreEqual("Anytown", ct.Get(address)); Assert.AreEqual("Doe", ln.Get(person)); Assert.AreEqual("Someville", ct.Set(address, "Someville").City); Assert.AreEqual("John", fn.Set(person, "John").FirstName); }
public static Lens <S, T, List <A>, List <A> > At <S, T, A>(this Lens <S, T, List <A>, List <A> > @this, int index) => Lens <S, T, List <A>, List <A> > .Of(s => List(@this.Get(s)[index]), (e, s) => @this.Set(List(@this.Get(s)[index] = e[0]), s));
public static Lens <S, T, C, D> Compose <S, T, A, B, C, D>(this Lens <S, T, A, B> @this, Lens <A, B, C, D> other) => Lens <S, T, C, D> .Of(@this.Get.Compose(other.Get), (d, s) => @this.Set(other.Set(d, @this.Get(s)), s));