// newSlice :: [a] -> (Integer,Integer) -> [a]
Array.prototype.newSlice = function(x,y) {
return this.slice(x,y)
}
// newSlice :: String -> (Integer,Integer) -> String
String.prototype.newSlice = function(x,y) {
return this.substring(x,y)
}
// even on a custom object
class LottoTicket {
constructor(...nums) { this.nums = nums }
newSlice(x,y) { return this.nums.slice(x,y) }
}
// newSlice :: (Array, String) a => (Integer,Integer) -> a -> a
const newSlice = (x,y) => F => F.newSlice(x,y)
// use it in prefix position
console.log(newSlice(1,2)([1,2,3,4])) // [2]
console.log(newSlice(1,2)("abcd")) // 'b'
console.log(newSlice(1,2)(new LottoTicket(9,8,7))) // [8]
// use it infix position
console.log([1,2,3,4].newSlice(1,2)) // [2]
console.log("abcd".newSlice(1,2)) // 'b'
console.log((new LottoTicket(9,8,7)).newSlice(1,2)) // [8]