Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Created August 19, 2018 17:37
Show Gist options
  • Save codingedgar/f0bed8f378e814ea1248fd5ff30b02f6 to your computer and use it in GitHub Desktop.
Save codingedgar/f0bed8f378e814ea1248fd5ff30b02f6 to your computer and use it in GitHub Desktop.
Ramda and TypeScript: Lenses
import { lens } from './lens';
test('adds 1 + 2 to equal 3', () => {
const unique = Symbol('nested')
expect(lens({
some: {
nested: {
value: unique
}
}
}))
.toBe(unique);
});
import { view, lensPath } from "ramda";
export function lens(obj: nestedType): Symbol {
return view<Symbol, nestedType>(lensPath<Symbol, nestedType>(['some', 'nested', 'value']), obj)
}
interface nestedType {
some: {
nested: {
value: Symbol
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment