These are chat archives for ramda/ramda

28th
Oct 2015
joneshf-work1
@joneshf-work1
Oct 28 2015 00:46
@xgrommx you could probably move some of it over to ramda.
It might be easier if you start with pulling those instance methods to functions
const fromKeyPress = code =>
  Observable.merge(
    fromKeyDown(code).map(true),
    fromKeyUp(code).map(false)
  ).shareValue(false)
const fromKeyPress = code =>
  Observable.merge(
    fromKeyDown(code).map(always(true)),
    fromKeyUp(code).map(always(false))
  ).shareValue(false)
const fromKeyPress = code =>
  Observable.merge(
    R.map(always(true), fromKeyDown(code)),
    R.map(always(false), fromKeyUp(code))
  ).shareValue(false)
etc.
David Chambers
@davidchambers
Oct 28 2015 04:00
FYI, R.T and R.F are shorthand for R.always(true) and R.always(false) respectively.
Martin Algesten
@algesten
Oct 28 2015 04:02
but R.I is not identity. :)
David Chambers
@davidchambers
Oct 28 2015 04:09
That is true. I felt a bit sneaky when I added S.I to Sanctuary after removing R.I from Ramda. ;)
Martin Algesten
@algesten
Oct 28 2015 04:10
and this one single alias would be really bad? i mean we don't need to open the flood gates for any alias. just this one very central one.
boxofrox
@boxofrox
Oct 28 2015 04:25
I just sprinkle R.I = R.identity; R.K = R.always; around my source files :scream:
Sometimes R.T bites me in the rear when forget it's a function and not a value.
Usually in conjunction with R.cond :facepunch:
Martin Algesten
@algesten
Oct 28 2015 04:45
R.K?
what is K?
David Chambers
@davidchambers
Oct 28 2015 05:03
S.K
Niloy Mondal
@niloy
Oct 28 2015 06:31
R.pipe(fn) === fn right?
Raine Virta
@raine
Oct 28 2015 07:25
what is the correct jsdoc @param for a lens value? Function or Lens?
Martin Algesten
@algesten
Oct 28 2015 07:34
@niloy sort of. it will curry and stuff.
Keith Nicholas
@keithn
Oct 28 2015 07:50
the most annoying thing about ramda is googling it keeps wanting to send me on holiday in cheap hotels
Raine Virta
@raine
Oct 28 2015 07:50
ha, why do you google ramda?
Keith Nicholas
@keithn
Oct 28 2015 07:51
in the hope someones solved my problem :)
half the trouble is knowing what functions exist
for instance, my current problem.... take an array of objects [{x:x, order:0},{x:x,order:0}] and i want to get a list where the "order" is set to the index position of where it is in the array
Keith Nicholas
@keithn
Oct 28 2015 07:58
problem is at the moment I want to ask something like I want a map like function but with an index
Raine Virta
@raine
Oct 28 2015 07:59
R.addIndex
Keith Nicholas
@keithn
Oct 28 2015 08:00
nice!
Niloy Mondal
@niloy
Oct 28 2015 08:32
Does anyone use lt, gt in its uncurried form?
boxofrox
@boxofrox
Oct 28 2015 12:12
I use <, > if I'm not currying.
Viktor Fröberg
@vikfroberg
Oct 28 2015 13:01
Is there a way in ramda to exclude a certain index in an array?
ie. return a new array without the object at a specific index
Raine Virta
@raine
Oct 28 2015 13:03
i don't think there's a function for doing that directly
Victor Cinaglia
@cinaglia
Oct 28 2015 13:03
R.remove
Raine Virta
@raine
Oct 28 2015 13:03
i stand corrected
Viktor Fröberg
@vikfroberg
Oct 28 2015 13:07
Well it doesn’t do that exactly, it takes a start index and a count.
We ended up making a new function from R.remove which only takes a index
@cinaglia thanks!
Raine Virta
@raine
Oct 28 2015 13:08
removeIndex = remove(__, 1) right?
Viktor Fröberg
@vikfroberg
Oct 28 2015 13:09
right!
Viktor Fröberg
@vikfroberg
Oct 28 2015 14:30
When do you guys use R.__ vs R.flip?
This message was deleted
Raine Virta
@raine
Oct 28 2015 14:30
R.__ most of the time
R.flip when not applying to any arguments
Viktor Fröberg
@vikfroberg
Oct 28 2015 14:31
That makes sense.
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:41
am i doing function log correctly?
function log(input) {
  console.log(input);
  return input
}
Raine Virta
@raine
Oct 28 2015 15:42
R.tap(console.log)
R.tap(console.log.bind(console)) in browser
Martin Algesten
@algesten
Oct 28 2015 15:43
@iamstarkov it's a trick question. logging is a side effect, so among the purists here, there is no such thing as "log correctly" ;)
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:44
yep
Martin Algesten
@algesten
Oct 28 2015 15:44
and check out treis
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:44
just want to throw smth which works in compose
good thing compose is the first example for treis ;)
Eric Gjertsen
@ericgj
Oct 28 2015 15:46
treis has saved my butt, really useful
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:47
will try it out
thanks
btw,
is console.log.bind(console)the same as r.bind(console.log)?
Martin Algesten
@algesten
Oct 28 2015 15:49
@raine is treis meant to be "trace" but phonetically in Finnish/swedish/not-english?
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:49
or is it custom application of r.partial
Martin Algesten
@algesten
Oct 28 2015 15:52
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:54
what is the difference between Function._.bind and r.bind?
i can read the ramda docs and know how F.bind is working
but still cant understand the diff
Martin Algesten
@algesten
Oct 28 2015 15:55
so. the ramda one you can use in composition.
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:55
so i can do r.bind(console.log, console) and it will works?
Martin Algesten
@algesten
Oct 28 2015 15:56
yes
i haven't used that one specifically, but given the type signature i assume it works.
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:56
oh, mb i got it
but i cant use r.bind to bind args
only context
Martin Algesten
@algesten
Oct 28 2015 15:57
yes
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:57
ty
Martin Algesten
@algesten
Oct 28 2015 15:57
no worries
Vladimir Starkov
@iamstarkov
Oct 28 2015 15:57
and if i want to bind args, then i prob should use partial
Martin Algesten
@algesten
Oct 28 2015 15:58
yes
ramda doesn't like multi-purpose functions.
Scott Sauyet
@CrossEye
Oct 28 2015 16:07
@davidchambers: so that's where R.I went. I thought I'd simply mislaid it.
Tobias Pflug
@gilligan
Oct 28 2015 16:48
@sinelaw biggest drawback with infernu for me right now would be lack of es6 support. Everything I do nowadays is es6
Vladimir Starkov
@iamstarkov
Oct 28 2015 18:27
how can i turn object into array with ramda?
{
  key1: val1
  key2: val2
} => [
  { key1: val1 }
  { key2: val2 }
]
i used groupBy and then want my array back to be able to iterate it
Scott Sauyet
@CrossEye
Oct 28 2015 18:35
You could
compose(map(apply(objOf)), toPairs)
Raine Virta
@raine
Oct 28 2015 18:36
beat me to it
Scott Sauyet
@CrossEye
Oct 28 2015 18:37
Really hate Gitter on Android.
Vladimir Starkov
@iamstarkov
Oct 28 2015 18:39
@CrossEye thank you
it saved tons of time
Denis Stoyanov
@xgrommx
Oct 28 2015 18:39
var o = {
  key1: 1,
  key2: 2
};
R.zipWith(R.objOf, R.keys(o), R.values(o))
Scott Sauyet
@CrossEye
Oct 28 2015 18:44
Nice
Denis Stoyanov
@xgrommx
Oct 28 2015 18:53
or this R.converge(R.zipWith(R.objOf), [R.keys, R.values])(o)
Raine Virta
@raine
Oct 28 2015 19:05
map (apply objOf) . toPairs is most intuitive to me
Raine Virta
@raine
Oct 28 2015 19:31
ramda will hit 3,000 stars any moment
David Chambers
@davidchambers
Oct 28 2015 19:53
I figured out how to support type classes in sanctuary-def! See README.md. I'd love your feedback. :)
joneshf-work1
@joneshf-work1
Oct 28 2015 19:56

@scott-christopher a couple days late, but I was just reminded of one reason why this conflated then is bad stuff. You lose out on free theorems with these conflated promises.

You have to go an prove all of these theorems for promises again (I think you can generalize it to anything that meets promises/a+ spec, but the point still remains).

joneshf-work1
@joneshf-work1
Oct 28 2015 20:04

For instance, given some function f :: Promise a -> Promise a, you have to prove

f(prom).then(g) === f(prom.then(g))

instead of relying on the fact that

f(prom).map(g) === f(prom.map(g))

would have fallen out of the Functor laws had this conflation not happened.

Raine Virta
@raine
Oct 28 2015 20:10
wanna humor me and explain why it matters?
Keith Nicholas
@keithn
Oct 28 2015 20:15
is it a good idea or not to introduce ramda functions into global scope?

i mean with lines like these

const notTwitter = url => url.host !== 'twitter.com';
const moveAllMinorsToOther = group => (length(group.links) < 5) ? 'other' : group.host;
 map(i => prop(head(keys(i)), i))
 mapObjIndexed((value, key) => ({ host: key, links: value })),
 map(i => ({ host: i[0], links: i[1] }))
 sortBy(group => group.host === 'other')

i think it can be wrapped into ramda methods somehow, but dont know how it can be done

Raine Virta
@raine
Oct 28 2015 20:49
should ramda have a variation of R.where that would expect the matched object to contain exactly the properties that the spec object has?
> R.where({ a: R.equals(1) }, { foo: 'bar' }) // anything goes
true
you could use it to make an object "schema"
> R.whereStrict({ a: R.is(Number) }, { a: 1, foo: 'bar' })
false
Noam Lewis
@sinelaw
Oct 28 2015 21:12
@gilligan can you narrow it down to specific features of ES6 ?
@raine that's a form of type-casing
@raine what would be the type of R.whereStrict?
Raine Virta
@raine
Oct 28 2015 21:14
same as R.where, I guess
Noam Lewis
@sinelaw
Oct 28 2015 21:14
actually, R.where has the same problem.
well, not really if we consider the object here as a map
Noam Lewis
@sinelaw
Oct 28 2015 21:20
R.where :: Map (a -> Bool) -> Map a -> Bool
joneshf-work1
@joneshf-work1
Oct 28 2015 21:25
@raine for the same reason why it matters that R.compose(f, R.compose(g, h)) === R.compose(R.compose(f, g), h). You can reason about things more generally, you can apply transformations more generally, you can provide sugar for some things, you can do more for free.
joneshf-work1
@joneshf-work1
Oct 28 2015 23:29
Is there a ($) like operator?
erm...not jquery
:t ($)
($) :: (a -> b) -> a -> b
Vladimir Starkov
@iamstarkov
Oct 28 2015 23:31
prop?
Scott Christopher
@scott-christopher
Oct 28 2015 23:47
@joneshf-work1 R.call
And regarding Promise, the main difference I can see between the existing functor laws and the A+ spec is if g were to return another Promise in f(prom).then(g) === f(prom.then(g)). Is that correct?
joneshf-work1
@joneshf-work1
Oct 28 2015 23:54
It might satisfy the theorem, but the pain is that you HAVE to prove it. You don't get it for free.
whereas, you don't have to prove that f(xs).map(g) === f(xs.map(g))for somethin glike arrays, or Maybe or whatever.
assuming they are law abiding, and f :: [a] -> [a] for arrays.
so like, R.map(someHugeComputation, R.take(3, xs)) === R.take(3, R.map(someHugeComputation, xs))
but it'd rather run the former than the latter.