Created
August 19, 2018 17:37
-
-
Save codingedgar/f0bed8f378e814ea1248fd5ff30b02f6 to your computer and use it in GitHub Desktop.
Ramda and TypeScript: Lenses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { lens } from './lens'; | |
test('adds 1 + 2 to equal 3', () => { | |
const unique = Symbol('nested') | |
expect(lens({ | |
some: { | |
nested: { | |
value: unique | |
} | |
} | |
})) | |
.toBe(unique); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { view, lensPath } from "ramda"; | |
export function lens(obj: nestedType): Symbol { | |
return view<Symbol, nestedType>(lensPath<Symbol, nestedType>(['some', 'nested', 'value']), obj) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface nestedType { | |
some: { | |
nested: { | |
value: Symbol | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment