Skip to content

How can I create a custom method with path? #159

@user753

Description

@user753

I have something like this

case class State(foo: Int)

class Store {
  var state = State(100)
  
  inline def set[A](inline path: State => A, value: A): Unit = {
    state = modify(state)(path).setTo(value)
  }

  
}

I what to implement set method so I could use it like this set(_.foo, 200)
But there is an error

    set(_.foo, 200)
    ^^^^^^^^^
Unsupported path element. Path must have shape: _.field1.field2.each.field3.(...), got: ((_$16: State) => _$16.foo)

Is there any way to do it?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions