All files / list selectors.js

100% Statements 15/15
75% Branches 3/4
100% Functions 5/5
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 26    5x   2x 5x     2x 1x 1x     2x 3x 3x 1x   2x     2x 1x 1x    
import curry from 'lodash/curry'
 
const root = state => state.list
 
export const getList = curry(function getList(list, state) {
  return root(state)[list] || []
})
 
export const len = curry(function len(target, state) {
  const data = getList(target, state)
  return data.length
})
 
export const lget = curry(function lget(target, index, state) {
  const data = getList(target, state)
  if (index > data.length - 1) {
    throw new Error(`index ${index} is out of bounds for list '${target}'`)
  }
  return data[index]
})
 
export const lrange = curry(function lrange(target, start, stop, state) {
  const data = getList(target, state)
  return data.slice(start, stop)
})