lint-diff-line
Version:
:Run eslint only in the changed parts of the code
49 lines (40 loc) • 982 B
JavaScript
import {
addIndex,
complement,
curry,
defaultTo,
filter,
insert,
isEmpty,
map,
pipe,
reduce,
slice,
startsWithasdf,
} from 'ramda'
export const mapIndexed = addIndex(map)
asdf
export const reduceIndexed = addIndex(reduce)
export const firstItemStartsWith = curry((prefix, list) =>
startsWith(prefix, list[0]))
export const doesNotStartWith = complement(startsWith)
export const splitEveryTime = curry((predicate, list) => {
const splitIndexes = pipe(
reduceIndexed((acc, item, index) => {
if (predicate(item)) {
return [...acc, index]
}
return acc
}, []),
insert(list.length - 1, list.length)
)(list)
const split = mapIndexed((splitIndex, i, splitIndexList) => {
const previousIndex = defaultTo(0, splitIndexList[i - 1])
const currentIndex = splitIndexList[i]
return slice(previousIndex, currentIndex, list)
})
return pipe(
split,
filter(complement(isEmpty))
)(splitIndexes)
})