These are chat archives for ramda/ramda

20th
Feb 2018
Brad Compton (he/him)
@Bradcomp
Feb 20 2018 00:09

@lucasconstantino There are a lot of different ways to do something like this.

I'd point you to converge, which allows you to fork your input, do different things with it, then bring it back together: https://goo.gl/izhh3H

converge(f, [g, h, i])(x) == f(g(x), h(x), i(x));

It works with more than one parameter too.

R.converge
joao@kapmug
@jay-jlm
Feb 20 2018 14:21
@lucasconstantino I have also been struggling with similar needs. If you scrollback a bit you may find my discussion with @lax4mike . My solution was to use R.map and R.zipObj (both used inside R.pipe)... but there are others such as R.converge, R.apply/R.unapply that might be used and that I don't fully understand right now
joao@kapmug
@jay-jlm
Feb 20 2018 14:30
Does anyone know if Monet.js is any less compatible with R.ramda than something like, say, Sanctuary.js?
the ramda-fantasy ReadME mentions a lot of alternative algebraic types libs, but for some reason Monet.js is not one of them
Bijoy Thomas
@bijoythomas
Feb 20 2018 14:35
Is monet.js compatible with the fantasy land spec? Don't see it being mentioned on its page
joao@kapmug
@jay-jlm
Feb 20 2018 14:44
according to some issue discussion I was reading it is but I haven't double checked. 1 min
@bijoythomas monet/monet.js#112
Found the references to the Fantasy land compatibility efforts in the change logs at the repo releases page: https://github.com/monet/monet.js/releases
joao@kapmug
@jay-jlm
Feb 20 2018 14:50
@davidchambers
David Chambers
@davidchambers
Feb 20 2018 15:26
What is your question for me, @jay-jlm?
Brad Compton (he/him)
@Bradcomp
Feb 20 2018 16:40
@jay-jlm Ramda Fantasy is not kept up to date, and its list of other libraries is not comprehensive. The source code suggests they are compatible.
Ben Briggs
@ben-eb
Feb 20 2018 20:42

Hi folks,

I was wondering if I could create a compose style function which logged out every step of the transformation? I got a basic thing working with intersperse but I would like to log the start and end values too. Here's what I have so far:

const composer = (...args) =>
  R.apply(R.compose, R.intersperse(R.tap(console.log.bind(console)), args));

const logger = composer(
  R.slice(1, Infinity),
  R.slice(1, Infinity),
);

logger('foo');

The actual functionality inside logger isn't important, this could be any sequence :)

Bijoy Thomas
@bijoythomas
Feb 20 2018 20:59
composeTrace = trace =>
    R.unapply(function(fns) {
      return R.apply(R.compose)(R.zipWith(R.o, R.repeat(trace, fns.length + 2), [identity, ...fns, identity]))
    })
Adds two identity functions at the ends of the functions to compose
example
let logger = console.log.bind(console)
composeTrace(tap(logger))(inc, add(9), multiply(10))(8)
Ben Briggs
@ben-eb
Feb 20 2018 21:10
@bijoythomas Nice! Thank you :)
functionalStoic
@functionalStoic
Feb 20 2018 21:11
Looking for the best way to remove the existence of a string within an array that is within an object that is within an array of these objects and then within an object
Mike Lambert
@lax4mike
Feb 20 2018 21:13
functionalStoic
@functionalStoic
Feb 20 2018 21:13
Hmm. Haven’t used dissocPath. Let me look into it
Mike Lambert
@lax4mike
Feb 20 2018 21:13
you can also use numbers in the path, eg ["a", 0, "c"]
in your case, you could use ["Frames", 1, "wallpos", 0]
functionalStoic
@functionalStoic
Feb 20 2018 21:15
So I have to find it first. So I don’t know the 1 and 0
Mike Lambert
@lax4mike
Feb 20 2018 21:15
ahh, hmm
functionalStoic
@functionalStoic
Feb 20 2018 21:15
Should I map to find it first with findIndex?
Mike Lambert
@lax4mike
Feb 20 2018 21:15
yeah, something like that
or maybe something recursive
to build that path
functionalStoic
@functionalStoic
Feb 20 2018 21:42
@lax4mike https://goo.gl/4c55jr So I may absolutely be using dissocPath incorrectly but it seems to mess with arrays that are within the path
If I use a number it returns the object with the number as a key
and converts the array into an object
Kurt Milam
@kurtmilam
Feb 20 2018 21:45
@functionalStoic do you want to remove all occurences of 'wall-frame-0' from all occurrences of wallpos?
functionalStoic
@functionalStoic
Feb 20 2018 21:45
yes
Kurt Milam
@kurtmilam
Feb 20 2018 21:46
I think there's a recent GitHub issue about the array -> object behavior of dissocPath and/or assocPath.
functionalStoic
@functionalStoic
Feb 20 2018 21:48
hmm
Kurt Milam
@kurtmilam
Feb 20 2018 22:00
Here's a solution using partial.lenses:
L.remove(['Frames', L.elems, 'wallpos', L.filter(R.equals('wall-frame-0'))], FDWD)
functionalStoic
@functionalStoic
Feb 20 2018 22:02
Nice. I’ve only messed with partial.lenses a bit. I love that playground.
Thanks for the help!
Kurt Milam
@kurtmilam
Feb 20 2018 22:02
You're welcome!
Ben Briggs
@ben-eb
Feb 20 2018 22:43

@bijoythomas Had a bit of a play around, what do you think of this one?

const trace = R.tap(console.log.bind(console))
const traceCompose = (...args) =>
  R.apply(
    R.compose,
    R.compose(
      R.append(trace),
      R.prepend(trace),
      R.intersperse(trace)
    )(args)
  );

It's supposed to be a drop in for compose when you want to debug

Only thing is could this code be point-free? Would that make it less readable?
I'm pretty new to this style of programming but I am enjoying it so far :)
Bijoy Thomas
@bijoythomas
Feb 20 2018 22:58
I think this will work
const trace = R.tap(console.log.bind(console))
 const traceCompose = R.unapply(
    R.compose(
      R.apply(R.compose),
      R.append(trace),
      R.prepend(trace),
      R.intersperse(trace)
    )
  )
It's prob not worth sacrificing readability to just make functions point-free
it would be better to make the function more re-usable by passing in the trace function. That way any kind of interception could be possible .. logging/auditing etc
Ben Briggs
@ben-eb
Feb 20 2018 23:12
Yeah, that's true; traceCompose = trace => R.unapply(...); this sort of thing I thought would be a nice drop in if you needed some quick debugging, logging everything all the time might be too noisy. :)