-1

Doesn't the Play framework have any lenses support included by default? Something like Monocole or those with Scalaz. Maybe there are recommended alternative approaches (along with their rationale) that I'm not aware of.

Scenario: I have an immutable, deeply nested object of a case class, and I want to copy it with a field changed somewhere in the object.

I'm looking specifically to do this very simply without needing much boilerplate, much like what lenses libraries like Monocole do.

I'm just surprised that Play framework doesn't have any support built in. Have I missed something? If not, is there any known plan for this support?

bjfletcher
  • 11,168
  • 4
  • 52
  • 67
  • 6
    Lenses are a somewhat orthogonal concern for a web framework don't you think? I think the philosophy is that you're very much encouraged to mix and match whatever existing libraries you like, so why not just use Monocole or Scalaz? – Mikesname Jan 31 '15 at 14:33

1 Answers1

5

Play doesn't include type unions and heterogeneous lists (shapeless).

Play doesn't include automatic resource management (scala-arm).

Play doesn't include lenses (Monocle or scalaz).

It's a MVC web framework, and limits itself to that problem space. However, any of these libraries would be easy to add to a Play project. Play uses SBT, so just add to the libraryDependencies of your build.sbt / Build.scala appropriately.

Paul Draper
  • 78,542
  • 46
  • 206
  • 285
  • My thought was that if we could do `employee.copy(surname = "Smith")` out of the box, why not the deeper parts of the object too? We could do deeper JSON accessors out of the box with Play framework. Why not objects too? I thought that it was standard enough to warrant inclusion. – bjfletcher Jan 31 '15 at 18:10
  • 1
    @bjfletcher, there has to be a sufficiently good reason it belong in *web framework*. Asking "Why is X not in the Play framework?" without explaining a strongly web-related thing you are doing, and why it is better if Play does it, isn't going to get you very far. The JSON example is the closest one to that, since it is decidedly very webby. I think there is already a way to do that though. – Paul Draper Jan 31 '15 at 18:17