Skip to content

Instantly share code, notes, and snippets.

@abiodun0
Last active June 26, 2017 07:23
Show Gist options
  • Select an option

  • Save abiodun0/ecb0c20f14e04359f4f704cd319a55ae to your computer and use it in GitHub Desktop.

Select an option

Save abiodun0/ecb0c20f14e04359f4f704cd319a55ae to your computer and use it in GitHub Desktop.
fp-ts-io_fantasy
import { IO } from 'fp-ts/lib/IO'
import * as io from 'fp-ts/lib/IO'
import * as array from 'fp-ts/lib/Array'
import { sequence } from 'fp-ts/lib/Traversable'
const add = (classes: string) => (sel: HTMLElement): IO<HTMLElement> => {
return new IO(() => {
sel.classList.add(classes)
return sel
})
}
const addClass = (classes: string) => (selectors: Array<HTMLElement>): IO<Array<HTMLElement>> => {
// ios :: Array<IO<HTMLElement>>
const ios = selectors.map(add(classes))
// ret :: IO<Array<HTMLElement>>
const ret = sequence(io, array)(ios)
return ret
}
export default addClass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment