by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 22:17
    CrossEye commented #2779
  • Jan 31 2019 21:04
    ArturAralin commented #2779
  • Jan 31 2019 20:08
    CrossEye commented #2779
  • Jan 31 2019 18:56
    buzzdecafe commented #2631
  • Jan 31 2019 18:09
    ArturAralin commented #2779
  • Jan 31 2019 16:18
    CrossEye commented #2779
  • Jan 31 2019 16:10
    CrossEye commented #2631
  • Jan 31 2019 16:06
    CrossEye commented #2777
  • Jan 31 2019 14:44
    ArturAralin opened #2779
  • Jan 31 2019 07:39
    inferusvv commented #2631
  • Jan 31 2019 03:07
    sespinozj commented #2771
  • Jan 31 2019 02:33
    machad0 commented #2771
  • Jan 31 2019 02:26
    JeffreyChan commented #2777
  • Jan 30 2019 14:30
    CrossEye closed #2777
  • Jan 30 2019 12:13
    vanyadymousky updated the wiki
  • Jan 30 2019 01:42
    JeffreyChan commented #2777
  • Jan 29 2019 21:06
    vanyadymousky updated the wiki
  • Jan 29 2019 16:28
    CrossEye commented #2777
  • Jan 29 2019 15:50
    mbostock commented #2772
  • Jan 29 2019 15:48
    CrossEye commented #2772
Marc Fogleman
@MFogleman

I have an applySpec and Promise problem

I am calling a database, getting back the document. I need to do a bunch of transforms based off the data gotten back, so I'm using an applySpec. It works great. But one of the fields in my spec needs to make a GET request to another server, and get the response. applySpec does not wait on promises. I figure there are 4 possible solutions

  1. There is a combination of wrapping this in async/awaits and R.then, to make this wait on the result, and I just dont know what it is
  2. This is a terrible anti pattern that I shouldnt be using at all
  3. Someone wrote a utility to solve this exactly (I found promise-apply-spec, but I think it may be a bit heavy for what I want)
  4. I'm going to need to hand roll either my own version of applySpec, or wrappers to handle this

If anyone has more experience in this or similar issues, feedback and guidance is appreciated

Ben Briggs
@ben-eb
@MFogleman You could also look into using a lazy data structure e.g. https://github.com/fluture-js/Fluture - not sure how well it would work with applySpec though to be honest
coffeefedora
@coffeefedora
i have a common paradigm, wondering if this has a functional term and maybe has a ramda function for it. I frequently do something like this: myObject[key] = myObject[key] || [];
so basically, get an existing array there or start one. i also do an object version of it
it's not exactly a long thing to type, but i was curious
kinda looks like a mergeRight maybe? myObject[key] = R.mergeRight(myObject[key], []);
but i'd love to just do: Init(myObject[key], []); and then its done
coffeefedora
@coffeefedora
although i'm dumb, it'd be Init(myObject, key, []);
Ben Briggs
@ben-eb
@coffeefedora I'd probably look at doing this when you want to extract the value out, then you can do propOr. e.g:
const results = R.propOr([], key, myObject);
In FP land we don't want to mutate our original object, so I think an Init function that has that interface would not be a good practice
coffeefedora
@coffeefedora
yeah that kind of makes sense. i set it the way i do to make looping easier when i am adding to the array
maybe i can re-organize my code and make it a little bit differently
Ben Briggs
@ben-eb
Yup :smile:
Hyunseok Oh
@algoshipda
  R.compose(
    R.fromPairs,
    R.zip(['x', 'y', 'z']),
    R.props(['a', 'b', 'c']),
  )
any equivalent function?
Twizzes
@Twizzes
@algoshipda That looks good to me, it seems to me there wouldn't be any much easier ways to specify a mapping like that. Are you looking for something that exhibits the same behavior in a different way?
Hyunseok Oh
@algoshipda
@Twizzes Can't with just one ramda function?
Ben Briggs
@ben-eb
@algoshipda 4 -> 3 with R.o(R.zipObj(['x', 'y', 'z']), R.props(['a', 'b', 'c']))
Oscar Bolmsten
@oscar-b
Is there a "preferred" style for pipe/compose when auto formatting? Any maintainer who would care to chime in? prettier/prettier#6921
Twizzes
@Twizzes
sorry if sanctuary is verbotten
Charles Hughes
@chughes87
anyone know a nice way to update all the keys in a given object? I need to prefix them all with a static string.. Object.entries and then R.zip comes to mind but I wish there was a cleaner way...
Brad Compton (he/him)
@Bradcomp
Something like this?
Charles Hughes
@chughes87
oh hell yall are already talking about this sorry for not reading :laughing:
Brad Compton (he/him)
@Bradcomp
Oh no prob! The wiki isn't well publicized
I try to bring it up whenever I can :smile:
Charles Hughes
@chughes87
@Twizzes do you strongly prefer Sanctuary to Ramda? I'm curious about it
Also I just wanna do a shout out. I've been using Ramda for a few months now and it is just glorious. Thanks to the developers/maintainers so much :pray:
Twizzes
@Twizzes
@chughes87 the sanctuary docs do a much better job at explaining the differences than I ever could:
For a direct function to function comparison, see: https://github.com/sanctuary-js/sanctuary/wiki/Ramda-to-Sanctuary
As you can see, sanctuary is more focused, and embraces further some of the concepts of functional programming, whereas ramda has a lot more utility functions and relaxes some of the constraints traditional FP enforces, making ramda somewhat more user friendly to folks from imperitive backgrounds
Twizzes
@Twizzes
Ramda is an easier sell to established teams using OOP, sanctuary is more for getting as close to FP in JavaScript as possible and a great way to learn FP for js devs
Patrick Laplante
@patbonecrusher
Hello all, really dumb question. How would you handle something like a socket in a composition chain. For instance, how would I do something like this but using functional composition.
Url = “localhost:8080”
connection = open_connection(url)
result = Send_data(connection, data)
raw_response = Get_response(connection)
response = parse(response)
Gerald
@jk121960
While I am not sure but it seems that get response should be receiving the result, if not you can curry it in but it could look like the following
        const sendData = R.curry(send_data)(R.__,data)
        const result = R.pipe(
            open_connection
            , sendData
            , get_response
            ,parse
        )(url);
sorry I missed some of the cases, get_response refers to Get_response and send_data refers to Send_data
Gerald
@jk121960
if you wish to actually use compose, change pipe to compose and reverse the argument function order
Charles Hughes
@chughes87
I'm curious how people here generally approach debugging their Ramda code? I've found the easiest/most fluid way to be putting a breakpoint at the top of a pipe call and playing around with the code in the debug console in vscode. I've wondered if I should try Emacs since it seems to support more repl based development that I'm trying to replicate here...
I've been wondering how feasible it might be to write a little VSCode extension that would put the outputs of each line inline in faded text when you're on a breakpoint. It seems to me like it would be pretty difficult
Kurt Milam
@kurtmilam

@chughes87 I sometimes use something like this:

const log = x => (console.log(x), x)

const pipeLog = (...fns) =>
  pipe(log, ...intersperse(log, fns), log)

pipeLog(inc, inc, inc)(0) // logs 0, 1, 2, 3

// also

pipe(dec, dec, log, dec)(100) // logs 98

REPL: https://bit.ly/2QKz2P1

Matt McKellar-Spence
@MattMS
tap(console.log) is pretty easy for quick debugging.
var b = pipe(add(1), tap(console.log), add(1));
b(1); // = 3 (and prints 2)
Charles Hughes
@chughes87
Ooo the pipeLog implementation there is pretty cool thanks!
Dimitri Mitropoulos
@dimitropoulos
I have a version of this I use too
const DEBUG_MODE = true;
let debugTimestamps: { [label: string]: number }[] = [];
const debugPipe = (label: string) => <T>(input: T) => {
  if (DEBUG_MODE) {
    debugTimestamps = [
      ...debugTimestamps,
      {
        [label]: performance.now(),
      },
    ];
    console.log({ [label]: input });
  }
  return input;
}
it's basically the same thing, but allows for some recording of timestamps, and then I have a startDebug or endDebug that basically just grabs the debugTimestamps and prints the performance numbers
Hyunseok Oh
@algoshipda
how can i make this function in ramda way?
const fn = x => id => R.prop(id, x);
Ian Hofmann-Hicks
@evilsoft
Try R.flip(R.prop), that should flip the arguments to R.prop
The C combinator I believe it is called