These are chat archives for ramda/ramda

4th
Jun 2016
David Chambers
@davidchambers
Jun 04 2016 01:45
The concat problem will be fixed in the next Ramda release. See #1756.
Gabe Johnson
@gabejohnson
Jun 04 2016 02:47
@ram-bot `always`
ram-bot
@ram-bot
Jun 04 2016 02:47
``[Function: f1]``
Gabe Johnson
@gabejohnson
Jun 04 2016 03:06
@ram-bot
``````const o = {
a: [ 7, 8, 9 ]
, b: [ 10 ]
, c: [ 1, 2, 3, 4, 5, 6 ]
};

const transform =
([src, dst, xform]) => pipe(view(src), xform, over(dst))(o);

const [aLens, bLens, cLens] = map(lensProp, ['a','b','c']);

const mappings = [
[aLens, bLens, flip(concat)],
[cLens, aLens, pipe(takeLast(3), always)],
[cLens, cLens, pipe(dropLast(3), always)]
];

apply(pipe, map(transform, mappings))(o);``````
ram-bot
@ram-bot
Jun 04 2016 03:07
`Unexpected token [`
Gabe Johnson
@gabejohnson
Jun 04 2016 03:08
@jamesbrown0: playing mini-golf
Jun 04 2016 04:32
This message was deleted
James Grayling
@jamesgrayling
Jun 04 2016 10:12
I’ve learnt a lot from your two solutions, @gabejohnson, thanks!
Jun 04 2016 15:06
Just for fun, here's one solution. @jamesbrown0 Note I would never use this code in real life ;)
``````const o = {
a: [ 7, 8, 9 ]
, b: [ 10 ]
, c: [ 1, 2, 3, 4, 5, 6 ]
};

converge(unapply(mergeAll), [
compose(objOf('a'), drop(3), prop('c')),
compose(objOf('b'), converge(concat, [prop('b'), prop('a')])),
compose(evolve({c: take(3)}), pick(['c']))
])(o);``````
Gabe Johnson
@gabejohnson
Jun 04 2016 16:51
@Bradcomp `converge` didn't know about that one
Rob Halff
@rhalff
Jun 04 2016 17:41
how do I composeP an array of Promises? do I need to use apply?
Jun 04 2016 17:45
@rhalff Do you have an array of Promises, or an array of Promise returning functions?
Rob Halff
@rhalff
Jun 04 2016 17:46
@Bradcomp: array of promise returning functions.
Jun 04 2016 17:47
Yeah, I think you can just use apply
Rob Halff
@rhalff
Jun 04 2016 17:47
ok, it seems like a very common construction though, maybe I'm just thinking wrong :)
Jun 04 2016 17:47
`R.apply(R.composeP)([array_of_functions])`
Rob Halff
@rhalff
Jun 04 2016 17:49
@Bradcomp: why is that preferable to `R.apply(R.composeP, [array_of_functions])`
good habit to always curry?
Jun 04 2016 17:50
Either way is fine
Rob Halff
@rhalff
Jun 04 2016 17:50
ok
Jun 04 2016 17:50
I use the two interchangeably, sorry
Rob Halff
@rhalff
Jun 04 2016 17:52
I'm just learning, this shall be my first line of ramda code.
Jun 04 2016 17:52
cool!
Rob Halff
@rhalff
Jun 04 2016 17:54
I was also wondering what fits fp better, Promises or just dealing with callbacks and wrapping those.
not sure if fp actually needs the features of promises.
Jun 04 2016 17:56
Well, I guess it depends on your preferences. If you want to go full FP there's `Future`'s, which are a more lawful variant of Promises.
Personally, I try to avoid callback based code as much as I can.
Rob Halff
@rhalff
Jun 04 2016 17:56
ok, good to know
Jun 04 2016 17:57
Rob Halff
@rhalff
Jun 04 2016 18:01
the ramda example is useful to me in this case.
@Bradcomp pipe is aware of promises?
Jun 04 2016 18:03
No, but there is `pipeP`
Denis Stoyanov
@xgrommx
Jun 04 2016 20:43
`pipeP` and `composeP` I think can be replaced with Kleisli composition but we need an alias for `then` like `chain = then` I'm not sure but will be this approach look working
Jun 04 2016 21:09
@xgrommx That's a benefit to using `Futures` or `Tasks` that are built with the FL spec in mind. Then you can use `chain` and `map` along with normal composition, or else use `pipeK` and `composeK`
Denis Stoyanov
@xgrommx
Jun 04 2016 21:10
@Bradcomp I know about `chain` and `map` but anyway we need only `of/pure` and `chain/bind` for functor, applicative, monad, lift, etc
Rob Halff
@rhalff
Jun 04 2016 22:13
``````// middleware with same function signature
const middleware = [
(req, res) => {
return {
...res,
test: req.ref1
}
},
(req, res) => {
return {
...res,
other: !req.ref1
}
}
];

// a reference object
const request = {
ref1: true
}

// intial object which needs to be build by the middleware
const response = {}

// runs the middleware
const runMiddleware = (req, res, funcs) => {
return funcs.reduce((res, func) => {
return func(res, req);
}, funcs)
}

console.log(runMiddleware(request, response, middleware))``````
I'm trying to be more `functional`, but I end up not needing ramda.
how can this be re-written using ramda and what will be the benefit.
didn't expect the paste to be that large btw.
Rob Halff
@rhalff
Jun 04 2016 22:19
it is functional in a way that it is stateless, it does not keep any local variables (besides the initial input), yet I assume the implementation of `runMiddleware`
is considered re-inventing the wheel and somehow somewhere violates the rule of functional programming?
Rob Halff
@rhalff
Jun 04 2016 22:27
can I delete that one? :-) it's the bugged version, the paste is wrong.
Jun 04 2016 22:37
You can delete it using the three dots on the right of the post
I don't know if there's a time limit
Rob Halff
@rhalff
Jun 04 2016 22:37
Jun 04 2016 22:38
Must be a time limit then...
Rob Halff
@rhalff
Jun 04 2016 22:42
yes seems so, I'm allowed to delete the last one.