javascript - Ramda return response as request body -


i'm new ramda, , wonder how simple task:

i have action , want return request body

router.post('/', ctx => {     ctx.body = ctx.request.body }) 

i tried lens, no success

const bodylens = r.lenspath(['ctx', 'body']) const reqlens = r.lenspath(['ctx','request', 'body'])  const set = r.pipe(r.view(reqlens), r.set(bodylens)) router.post('/', ctx => {     set(ctx)(ctx)     ctx.body = ctx.request.body }) 

how make work in elegant way?

is want achieve?

const ctx = {    request: {      body: 'hello'    }  }    const bodylens = r.lenspath(['body'])  const reqlens = r.lenspath(['request', 'body'])    const _set = r.pipe(r.view(reqlens), r.set(bodylens))    console.log(_set(ctx)(ctx))
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"></script>

update if want achieve ctx => _set(ctx)(ctx) in pointfree style, how simplify functions , import converge?

const ctx = {    request: {      body: 'hi'    }  }    const _set2 = r.converge(r.assoc('body'), [r.path(['request', 'body']), r.identity])    console.log(_set2(ctx));
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"></script>


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -