goggles icon indicating copy to clipboard operation
goggles copied to clipboard

Support for unapplied get/set?

Open kenbot opened this issue 8 years ago • 0 comments

A common Monocle idiom, currently unsupported by Goggles, is composing lens set/modify expressions before the object is applied. This returns an endofunction, with pleasing compositional properties. For instance:

val x: Item => Item = itemQtyLens.modify( _ + 1) andThen itemPriceLens.set(4)

It also aligns with the common FP intuition of "compose first, many times; execute last, once".

Is there some way to support this idiom in get/set modes without making everything weird and complicated? One way might be to allow a from[MyType] type hint (as per #31) in the left-most position instead of the source object, which would return an endofunction rather than the usual result. This might prove a confusing special case though.

kenbot avatar Mar 19 '17 11:03 kenbot