Skip to content

Conversation

@wookietreiber
Copy link
Contributor

  • provides LensFamily.modo which returns the old value (as an alternative to LensFamily.mods which returns the new value)
  • provides LensFamily.assigno which returns the old value (as an alternative to LensFamily.assign which returns the new value)
  • both modo and assigno are provisional names
  • both modo and assigno do not have a symbolic alias yet

I'd welcome suggestions for the final names of these new variants as well as suggestions for the symbolic aliases.

- provides `LensFamily.modo` which returns the old value (as an alternative to `LensFamily.mods` which returns the new value)
- provides `LensFamily.assigno` which returns the old value (as an alternative to `LensFamily.assign` which returns the new value)
- both `modo` and `assigno` are provisional names
- both `modo` and `assigno` do not have a symbolic equivalent yet
@wookietreiber
Copy link
Contributor Author

BTW motivation for this patch is to reduce the following example:

val emptySv1: State[Game,Cards] = for {
  stack  State.gets[Game,Cards](_.stack)
  _      stackL := Cards()
} yield stack

... to this much shorter one:

val emptySv2: State[Game,Cards] = stackL.assigno(Cards())

@wookietreiber
Copy link
Contributor Author

AFAIK from looking at the core/src/main/scala/scalaz/Lens.scala source there is nothing like this yet.

@larsrh
Copy link
Contributor

larsrh commented Apr 8, 2013

@tonymorris @pthariensflame Could you have a look at that please?

@pthariensflame
Copy link
Contributor

I'm fine with modo and assigno. The Haskell lens package uses < prefixes for operations that return the old state, so modo would be <%= and assigno would be <:=.

@pthariensflame
Copy link
Contributor

Also, I'd rather tighten up the implementations as:

def modo(f: B1 => B2): IndexedState[A1, A2, B1] = 
  IndexedState(a => {
    val c = run(a)
    val o = c.pos
    (c put f(o), o)
  })

def assigno(b: => B2): IndexedState[A1, A2, B1] =
  modo(_ => b)

@wookietreiber
Copy link
Contributor Author

Thanks for the comments, @pthariensflame. The commits above apply the suggested changes.

@pthariensflame
Copy link
Contributor

You seem to have left the type parameter on modo and its synonym. They are provably unnecessary. :)

larsrh added a commit that referenced this pull request Apr 12, 2013
@larsrh
Copy link
Contributor

larsrh commented Apr 12, 2013

Merged as 620787c. Thanks!

@larsrh larsrh closed this Apr 12, 2013
larsrh pushed a commit that referenced this pull request Jul 4, 2013
- provides `LensFamily.modo` which returns the old value (as an alternative to `LensFamily.mods` which returns the new value)
- provides `LensFamily.assigno` which returns the old value (as an alternative to `LensFamily.assign` which returns the new value)

Cherry-picking pull request #324 (6130683)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants