Skip to content

Instantly share code, notes, and snippets.

@jLouzado
Last active July 1, 2020 18:28
Show Gist options
  • Save jLouzado/645bb114ade86b1769577d727ce9da29 to your computer and use it in GitHub Desktop.
Save jLouzado/645bb114ade86b1769577d727ce9da29 to your computer and use it in GitHub Desktop.
Ramda: Toggle Key of a Record using Lenses
type key = string
type Records = Record<key, boolean>
const records: Records = {
foo: false,
bar: false
}
// key -> ((A -> B) -> Records -> Records)
const setter = R.converge(
R.over,
[R.lensProp, R.always(R.not)]
)
// key -> Records -> Records
const toggleKey = R.useWith(
R.apply, [
setter, R.identity
]
)
toggleKey('foo', records) // Expected => {foo: true, bar: false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment