// https://stackoverflow.com/a/42242601/9034699

// From original answer: Stack
const stackPush = (x, xs) => f => f(x,xs)
const stackPop = s => s((x,xs) => [x,xs])

// From a looooong effort on my side. 
// It is not efficient, or usable. But the goal was a proof of concept: To figure out a way to do this using similar method.
const countQ = Q => Q((prevEl, prevQ) => 1 + (prevQ ? countQ(prevQ) : 0)) 
const enQ = (el, Q) => f => f(el, Q, Q ? countQ(Q): 0)
const first = (Q, count) => Q((lastEl, lastQ) => (count === 0 ? lastEl : first(lastQ, count - 1)))
const deQ = Q => Q ? Q((lastEl, lastQ, lastCount) => [first(Q, lastCount), lastCount ? f => f(lastEl, lastQ, lastCount - 1) : null]) : null