These are chat archives for ramda/ramda

5th
Dec 2018
Kurt Milam
@kurtmilam
Dec 05 2018 00:21 UTC
:D
Kurt Milam
@kurtmilam
Dec 05 2018 01:19 UTC
Is there a function that works like this:
fn([add(1), add(10)], 1) // -> [2, 11]
I know I can use ap if I wrap the second argument in an array, but I'm looking for a function that doesn't require the second argument to be contained in an array.
Johnny Hauser
@m59peacemaker
Dec 05 2018 02:00 UTC
almost pipe
right?
I had been thinking I'd prefer a unary pipe anyway
pipe ([ add(1), add(10) ]) (1)
oh wait
nm
you want an array result
Kurt Milam
@kurtmilam
Dec 05 2018 08:11 UTC
This does the trick:
map ( applyTo ( 1 ) )
// -> [2, 11]
Kurt Milam
@kurtmilam
Dec 05 2018 09:02 UTC

For clarification, this is what I'd like to have:

const fn = fns => x => map ( applyTo ( x ) ) ( fns )

Easy to write on my own, but I'd prefer to use an existing function if there is one. Also, if I need to write it myself, I'd love some tips for what to name it :)

TeerawatBoonrat
@TeerawatBoonrat
Dec 05 2018 11:48 UTC
Hi
Alexander Lichter
@manniL
Dec 05 2018 11:49 UTC
Hey :wave:
Scott Sauyet
@CrossEye
Dec 05 2018 14:31 UTC

@m59peacemaker: We know the natural, counting numbers like 1, 2, 3, ... And it's easy enough to extend that to the integers, ..., -3, -2, -1, 0, 1, 2, 3, .... And we're familiar with fractions (rational numbers) that also include -1/2 and 355/113. The reals are all those plus the numbers in between that can't be expressed by a fraction, things like √2, or π. There are many more real numbers than rational ones. (There are other collections in between, such as the algebraic numbers, which are mostly interesting to mathematicians.)

Real numbers are the logical units to use when discussing time (and no, I won't debate this point with my physicist son!) Time blocks are continuously divisible into smaller ones, so the reals, which easily represent a continuum, simply make sense.

Kurt Milam
@kurtmilam
Dec 05 2018 15:29 UTC
I'm partial to the imaginary numbers, like √-5 :)
Ben Briggs
@ben-eb
Dec 05 2018 15:30 UTC
@kurtmilam Yes, R.juxt works like this
juxt([add(1), add(10)])(1) // [2, 11]
Kurt Milam
@kurtmilam
Dec 05 2018 15:32 UTC
:boom: That's the ticket! Time to say goodbye to my mapApplyTo :D
Thanks - I've used juxt, but it's been a while.
Ben Briggs
@ben-eb
Dec 05 2018 15:33 UTC
:smiley: :thumbsup:
Kurt Milam
@kurtmilam
Dec 05 2018 15:34 UTC
We need a Roogle (Hoogle for Ramda).
Ben Briggs
@ben-eb
Dec 05 2018 15:35 UTC
Kurt Milam
@kurtmilam
Dec 05 2018 15:37 UTC
Thanks - that's also handy. Bookmarked.
Ben Briggs
@ben-eb
Dec 05 2018 15:37 UTC
You're welcome!
Scott Sauyet
@CrossEye
Dec 05 2018 16:17 UTC
I really do want to try to create a Hoogle, but we'd have to tame our signatures first.
Dec 05 2018 16:36 UTC
I've still never used juxt and am not sure how it works :stuck_out_tongue:
Kurt Milam
@kurtmilam
Dec 05 2018 17:06 UTC
I'm doing a bunch of plane geometry with line segments, points, etc. juxt makes it easy to turn an array of line segments into an array of tuples consisting of the segment length and segment starting point.
Scott Sauyet
@CrossEye
Dec 05 2018 17:06 UTC
R.juxt([f, g, h]) //=> (a, b, ...) => [f(a, b, ...), g(a, b, ...), h(a, b, ...)]
Kurt Milam
@kurtmilam
Dec 05 2018 17:07 UTC
Now I'm trying to figure out a getSegment length function that will work with segments in any number of dimensions.
FP is a code golfer's nightmare / paradise, depending on how you look at it :)
Rakesh Pai
@rakeshpai
Dec 05 2018 17:12 UTC
@kurtmilam Haha. +1. I'm actually less productive with Ramda thanks to the code-golfing. But the code looks so much better! (sometimes)
Scott Sauyet
@CrossEye
Dec 05 2018 17:15 UTC
I have to fight hard sometimes to avoid code-golfing. Make it readable, damn it, Scott!
Kurt Milam
@kurtmilam
Dec 05 2018 17:16 UTC
:thumbsup:
Dec 05 2018 17:17 UTC
:angel:
Kurt Milam
@kurtmilam
Dec 05 2018 17:28 UTC
I think this will get the length of any segment in any number of dimensions:
const getSegmentLength =
S.pipe([
R.apply ( R.zipWith ( R.subtract ) ),
R.map( x => x * x ),
R.sum,
Math.sqrt
])
// S is Sanctuary
I wrote one that worked in 2 dimensions, which is probably all I'll ever need, but I just can't leave good enough alone :laughing:
Scott Sauyet
@CrossEye
Dec 05 2018 17:57 UTC
@kurtmilam: it certainly looks right.
Kurt Milam
@kurtmilam
Dec 05 2018 17:59 UTC
:thumbsup: I get a special satisfaction from writing software that involves a little math (although this is super simple math).
Dec 05 2018 18:01 UTC
Once I had to use some pretty interesting discrete math for a practical project. It isn't that common for what I do (web dev). I still use it in the "tell us somethingyou're proud of" part of interviews
Scott Sauyet
@CrossEye
Dec 05 2018 18:04 UTC
Yeah, I love having those stories. Mine, believe it or not, was about writing a simplified XML parser in COBOL.
Dec 05 2018 18:05 UTC
Oh that's fun
I am hoping that I can spend enough time on the server framework I am writing that I will be able to point to that
Scott Sauyet
@CrossEye
Dec 05 2018 18:06 UTC
Nice to be working on something that might end up being one of those stories!
The most fun was explaining to the COBOL people that the XML parser they were using (the built in mainframe one in 2002) sucked and that we could do it better... and then proving it in three days. They'd believed no one could do it better than IBM. But their parser took the worst of both SAX and DOM. It loaded the entire document in memory, then delivered it only as a stream of events. It was really easy to just create a SAX parser (huge documents) as a state machine in Java, then port that code to COBOL.
Dec 05 2018 18:10 UTC
That's really interesting
Scott Sauyet
@CrossEye
Dec 05 2018 18:10 UTC
So what did you use discrete math for? And what sort of discrete math?
Dec 05 2018 18:13 UTC

Oh, so I was building an appointment scheduling app, and there were rules dictating when people were allowed to schedule appointments. We needed to be able to efficiently determine whether or not two recurring appointments would overlap in the future, based on the recurrence schedule of each appointment.

It's easy for stuff like weekly appointments, but once you start with stuff like:

Appt A is every 5 weeks and appt B is every 12 weeks at the same time and day and Appt A starts 4 weeks before Appt B

it gets tricky

Not being a mathemetician, I wasn't aware of existing work that handled the overlapping of values on two different modular ... scales?
It's been a while, but I was able to derive some laws depending on the coprimality of the modulus and the distance between the start dates
This message was deleted
This message was deleted
Dec 05 2018 18:19 UTC
I think gitter regex replacement is broken :-(
Scott Sauyet
@CrossEye
Dec 05 2018 18:21 UTC
That's funny; I did something similar on my last job. It was for scheduling recurring jobs, not appointments, but very similar. Although I have a math background, I ended up simply checking every occurrence until the termination date rather than trying what you did. But yes, coprimality would be the key mathematically.
Dec 05 2018 18:26 UTC
It was pretty fun, and efficient for the most important use case.
Daniel Pereira
@dpereira411
Dec 05 2018 22:36 UTC

const t = {a: 'p', p: 'g'}
prop(prop('a')(t))(t)

is there a way to write this without calling (t) twice?

expected output is 'g'
Dec 05 2018 22:41 UTC
@ram-bot
converge(prop, [prop('a'), identity])({a: 'b', b: 'g'})
ugh, rambot is down
but that works
chain(prop, prop('a'))({a: 'b', b: 'g'})
That does too

From the docs:

If second argument is a function, chain(f, g)(x) is equivalent to f(g(x), x).

Daniel Pereira
@dpereira411
Dec 05 2018 22:44 UTC
:) thanks
:bowtie: I finally got to use the chain instance for functions
Interesting, chain(fn, identity) is the W combinator :)