Skip to content

Instantly share code, notes, and snippets.

@DrBoolean
Last active January 22, 2016 01:36
Show Gist options
  • Select an option

  • Save DrBoolean/83737ad6c1407ac1f68a to your computer and use it in GitHub Desktop.

Select an option

Save DrBoolean/83737ad6c1407ac1f68a to your computer and use it in GitHub Desktop.
Lens8
// immutable data
const addrs = List.of(Map({street: '99 Walnut Dr.', zip: '04821'}), Map({street: '2321 Crane Way', zip: '08082'}))
const user = Map({id: 3, name: 'bob', addresses: addrs})
// lenses
const addresses = immLens('addresses')
const street = immLens('street')
const allStreets = compose(addresses, mapped, street)
// getUser :: Int -> Task Error User
const getUser = id => new Task((rej, res) => setTimeout(() => res(user), 400))
// profilePage :: User -> Html
const profilePage = compose(map(x => `<span>${x.get('street')}<span>`), view(addresses))
// updateUser :: User -> User
const updateUser = over(allStreets, replace(/\d+/, '****'))
// renderProfile :: User -> Html
const renderProfile = compose(map(compose(profilePage, updateUser)), getUser)
renderProfile(1).fork(console.log, console.log)
//List [ "<span>**** Walnut Dr.<span>", "<span>**** Crane Way<span>" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment