All files / set selectors.js

100% Statements 16/16
100% Branches 2/2
100% Functions 6/6
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25    33x   2x 33x   2x 3x     2x 3x 3x     2x 1x     2x 26x 26x 26x  
import curry from 'lodash/curry'
 
const root = state => state.set
 
const emptySet = []
const getSet = curry((name, state) => root(state)[name] || emptySet)
 
export const scard = curry(function scard(name, state){
  return getSet(name, state).length
})
 
export const sisMember = curry(function sisMember(name, value, state){
  const set = getSet(name, state)
  return set.indexOf(value) > -1
})
 
export const smembers = curry(function smembers(name, state){
  return getSet(name, state)
})
 
export const srand = curry(function srand(name, state){
  const set = getSet(name, state)
  const idx = Math.floor(Math.random()*set.length)
  return set[idx]
})