1.0.2 • Published 5 years ago

@sharyn/util.cycle v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

🌹 cycle

cycle returns the next value of a set of values, and defaults to the first one.

import cycle from '@sharyn/util/cycle'
// or import { cycle } from '@sharyn/util'

cycle(current, 'a', 'b', 'c') // if current === 'a', returns 'b'
cycle(current, 'a', 'b', 'c') // if current === 'b', returns 'c'
cycle(current, 'a', 'b', 'c') // if current === 'c', returns 'a'
cycle(current, 'a', 'b', 'c') // if current === 'x', returns 'a'

Deep equality is supported:

cycle({ a: 2 }, { a: 1 }, { a: 2 }, { a: 3 }) // { a: 3 }

cycle is part of @sharyn/util