These are chat archives for ramda/ramda

23rd
Oct 2015
Scott Sauyet
@CrossEye
Oct 23 2015 00:02
No, and I'm not settled on doing so. But there is something more satisfying in registering as Monad with chain and of, and then knowing we get Functor's map for free, and that it is a Functor, etc.
Scott Christopher
@scott-christopher
Oct 23 2015 00:03
Yeah, I'm also interested in working out a clean way to determine what can be derived
Jethro Larson
@jethrolarson
Oct 23 2015 00:03
Are you looking to only support fantasy land stuff or any arbitrary interface fusion?
Scott Sauyet
@CrossEye
Oct 23 2015 00:03
Perhaps we can do that just by the registrations of the names.
Trying to do something generic, but with an eye to FL first.
similar to what I remember you doing some weeks back, I believe.
Jethro Larson
@jethrolarson
Oct 23 2015 00:04
There seems to be a relationship between this and operator overloading
Scott Sauyet
@CrossEye
Oct 23 2015 00:05
ok, got to go code. Can't get back to this tonight, but want to clear off some other things so that I can get back to it soon.
ttyl
Scott Christopher
@scott-christopher
Oct 23 2015 00:05
:wave:
Jethro Larson
@jethrolarson
Oct 23 2015 00:05
bbfn
Jethro Larson
@jethrolarson
Oct 23 2015 00:13
there's no functional testing framework for JS, is there?
Scott Christopher
@scott-christopher
Oct 23 2015 00:16
for property testing?
There's an example of how we've used it in RF here: https://github.com/ramda/ramda-fantasy/blob/master/test/either.test.js
var leftArb = function(arb) {
  return arb.smap(Either.Left, R.prop('value'), R.toString);
};
var rightArb = function(arb) {
  return arb.smap(Either.Right, R.prop('value'), R.toString);
};
var eitherArb = function(arb) {
  return jsv.oneof([leftArb(arb), rightArb(arb)]);
};
That allows for the creation of arbitrary instances of Either (and Left/Right)
Scott Christopher
@scott-christopher
Oct 23 2015 00:23
Which can then be used to test the various laws, for example:
// An arbitrary `Either Int Int`
var eNatArb = eitherArb(jsv.nat);

// An arbitrary `* -> Int`
var fnNatArb = jsv.fn(jsv.nat);

var compose = (obj, f, g) =>
  eq(obj.map(x => f(g(x))), obj.map(g).map(f));

jsv.assert(jsv.forall(eNatArb, fnNatArb, fnNatArb, compose));
Jethro Larson
@jethrolarson
Oct 23 2015 00:24
well. I'd just expect that if your test file doesn't export then there should be no output
Scott Christopher
@scott-christopher
Oct 23 2015 00:25
Do you mean there is nothing exported from either.test.js?
Scott Christopher
@scott-christopher
Oct 23 2015 00:31
The test runner that is used is https://mochajs.org, which defaults to using the BDD-style describe interface
There is also an exports interface that could be used if desired, but that need hasn't surfaced yet.
The propery-based testing library that provides the concept of arbitraries and the forall assertions in that example is jsverify.
I'm imagining something like this
I'm pretty flexible on the details
test frameworks typically look like too much magic to me
a test file should return either test that will be run or the result of running the test
the test should be a function
Scott Christopher
@scott-christopher
Oct 23 2015 00:37
^ was the alternative exports interface that Mocha offers
You could alternatively skip the test runner and use something like jsverify directly
Jethro Larson
@jethrolarson
Oct 23 2015 00:40
I want the benefit of nice console output and other consumable reports
[1,2,3].indexOf(4).should.equal(-1);
what's this magic
Scott Christopher
@scott-christopher
Oct 23 2015 00:41
You don't have to use that style of assertion.
Jethro Larson
@jethrolarson
Oct 23 2015 00:41
but no really, did they modify the object prototype?
Scott Christopher
@scott-christopher
Oct 23 2015 00:42
:shrug: I've never bothered looking into it, because I'm not a fan of it either
Jethro Larson
@jethrolarson
Oct 23 2015 00:42
I like knowing how my tools work :)
Scott Christopher
@scott-christopher
Oct 23 2015 00:42
There's also something like https://github.com/fantasyland/fantasy-check
It looks like that style of assertion that they use in the examples is from https://github.com/shouldjs/should.js
So it's not a part of Mocha by default (AFAIK)
Jethro Larson
@jethrolarson
Oct 23 2015 00:46
that's good. I'm frickin done with magic
Scott Christopher
@scott-christopher
Oct 23 2015 00:46
Yeah, I've never been a fan of the cute test APIs
Jethro Larson
@jethrolarson
Oct 23 2015 00:47
there has to me a common ground between expressive, usable, and pure
Scott Christopher
@scott-christopher
Oct 23 2015 00:48
Jethro Larson
@jethrolarson
Oct 23 2015 00:48
At least with promises in ES6 there's a standard way to model async processes
nodeunit looks less weird but it's clearly dependent on abstract machinations
Scott Sauyet
@CrossEye
Oct 23 2015 00:58
On the other hand, this reads well, and it's easy enough to understand how it's built:
expect([1,2,3].indexOf(4)).toBe(-1);
Jethro Larson
@jethrolarson
Oct 23 2015 01:02
yes, that's fine
however, unless it's attached to a return, there's magic
John-David Dalton
@jdalton
Oct 23 2015 01:08
less magic means less interference with your stuff : )
I'd hate for the testing framework to be the pain point in, well testing
would potentially cause problems with Ramda which dispatches because of added test sugar to built-ins
Jethro Larson
@jethrolarson
Oct 23 2015 01:10
In my observation engineers underengineer their testing. I think that's further hindered by magical test suites
John-David Dalton
@jdalton
Oct 23 2015 01:11
I give qunit a lot of grief but I'm digging its 2.0 flavor
available in its 1.19 too
Jethro Larson
@jethrolarson
Oct 23 2015 01:11
I understand the fantasy of linguistically inspired test descriptions
Expect (new Dog()) can bark
Less nice
can(new Dog(), "bark")
but waay less magic
John-David Dalton
@jdalton
Oct 23 2015 01:14
assert.deepEqual(value, expected, label) weee
organize to taste : P
Jethro Larson
@jethrolarson
Oct 23 2015 01:15
assert.truly.madly.deeply
John-David Dalton
@jdalton
Oct 23 2015 01:16
++savage-garden but meh
I'm of if you dig it and it gets you writing tests then whatever : )
Scott Christopher
@scott-christopher
Oct 23 2015 01:16
I quite like the way property tests read: forall(arbitraryThing, somePropertyIsSatisfied)
Jethro Larson
@jethrolarson
Oct 23 2015 01:16
I wasn't advocating for that style, just making joke
Scott Christopher
@scott-christopher
Oct 23 2015 01:17
I'm of if you dig it and it gets you writing tests then whatever
+1
Jethro Larson
@jethrolarson
Oct 23 2015 01:18
I want to test the way I code
Martin Algesten
@algesten
Oct 23 2015 02:27
i use chai, but only the assert style, not bdd. assert.isTrue(someThing)
i was using the bdd style for a long while. but it's too verbose. i don't like writing lots. expect(someThing).to.be.undefined however i didn't find the magic that bothersome when it's isolated to my tests.
Niloy Mondal
@niloy
Oct 23 2015 06:02
Why doesn't R.chain concat string?
Raine Virta
@raine
Oct 23 2015 06:43
i like simple equal(actual, expected) assertions, and i don't think code should read like english. you already know how to check if an item exists in a list so you should be able to use that knowledge when writing tests instead of having to learn another DSL
essentially just to get pretty assertion errors
Raine Virta
@raine
Oct 23 2015 06:51
expect(obj).to.have.property('foo') vs. assert.property(obj, 'foo') vs. ok(has('foo', obj))
Scott Christopher
@scott-christopher
Oct 23 2015 07:17
@niloy because strings in JS aren't just an alias for a list of chars like in other languages
Niloy Mondal
@niloy
Oct 23 2015 07:19
Well, yeh, but we "can" make chain concat strings, I dont see any reason not to, nothing technically is holding back
Scott Christopher
@scott-christopher
Oct 23 2015 07:19
if a string were to be mapped over, applying a String -> Number function to each character, would you want that to attempt to join as a string afterwards?
Niloy Mondal
@niloy
Oct 23 2015 07:20
Nope, but am talking specifically about this case, chain on String output
Scott Christopher
@scott-christopher
Oct 23 2015 07:20
chain can't be sure the resulting list contains only Strings either, without scanning each element of the list
Niloy Mondal
@niloy
Oct 23 2015 07:22
chain can always be sure the result gives a array-like thing, just call concat on it
Both normal Array and String support concat
Scott Christopher
@scott-christopher
Oct 23 2015 07:27
If you want to treat a String as a list of Chars, that's fine. But there is nothing preventing the function passed to chain from changing that to a list of Numbers. So should it attempt to concat those Numbers together?
And chain isn't restricted to lists. It will also work for other monads like functions, or other types that implement the fantasy land spec for monads.
Niloy Mondal
@niloy
Oct 23 2015 07:53
The transform function of chain has signature a -> [b], which means we have a guarantee that the output is a array-like thing.
And chain isn't restricted to lists
Do you have an example of this?
Asking for learning purpose
Martin Algesten
@algesten
Oct 23 2015 07:58
@niloy the end result of chain is passed into https://github.com/ramda/ramda/blob/v0.18.0/src/internal/_makeFlat.js ... which is, imo, a better idea than relying on the built in Array.prototype.concatsince the latter has all sorts of strange edge cases.
Raine Virta
@raine
Oct 23 2015 07:59
var addFour = a => b => c => d => a + b + c + d;
var uncurriedAddFour = R.uncurryN(4, addFour);
uncurriedAddFour(1, 2, 3, 4); //=> 10
uncurriedAddFour(1, 2, 3); // ???
what do you expect as return value
Martin Algesten
@algesten
Oct 23 2015 08:00
NaN? undefined?
Raine Virta
@raine
Oct 23 2015 08:00
it's function!
Martin Algesten
@algesten
Oct 23 2015 08:00
special! :)
Niloy Mondal
@niloy
Oct 23 2015 08:00
@algesten I am not really concerned about the actual concating mechanism as long as it happens
Raine Virta
@raine
Oct 23 2015 08:00
uncurry -> returns a curried function
i was expecting NaN as well
Martin Algesten
@algesten
Oct 23 2015 08:03
does uncurriedAddFour(1, 2, 3)(4); work?
Scott Christopher
@scott-christopher
Oct 23 2015 08:11
@niloy The type signature for chain is slightly misleading, as it doesn't only work on lists.
Denis Stoyanov
@xgrommx
Oct 23 2015 08:12
Anybody tried F#?
Scott Christopher
@scott-christopher
Oct 23 2015 08:12
The problem is changing the signature to Monad m => (a -> m b) -> m a -> m b is a lot to take in for newcomers.
Another example of where chain can be used is with the Maybe type offered by Sanctuary: https://github.com/plaid/sanctuary#maybechain--maybe-a--a---maybe-b---maybe-b
Which is a way of capturing the context of failure, while lists/arrays offer a context of nondeterminism.
Niloy Mondal
@niloy
Oct 23 2015 08:17
Errr.... I am not an expert, but chain is flatMap, what sanctuary is doing is just map
But I am probably wrong
David Chambers
@davidchambers
Oct 23 2015 08:25
@niloy, map is different. Compare:
Niloy Mondal
@niloy
Oct 23 2015 08:26
Thanks, reading đź‘Ť
David Chambers
@davidchambers
Oct 23 2015 08:26
In one case the transformation is a -> Maybe b; in the other it is simply a -> b.
Viktor Fröberg
@vikfroberg
Oct 23 2015 11:21
Hi guys, are there any equalent of guards in ramda?
Martin Algesten
@algesten
Oct 23 2015 11:23
ifElse? or what do you expect it to do @vikfroberg?
Viktor Fröberg
@vikfroberg
Oct 23 2015 11:24
similar to a switch-statement
Raine Virta
@raine
Oct 23 2015 11:24
cond
Viktor Fröberg
@vikfroberg
Oct 23 2015 11:24
Thanks <3 @raine
Martin Algesten
@algesten
Oct 23 2015 11:26
cond is funny because it actually does return undefined if no condition matches. quite unlike ramda :) ... perhaps the signature ought to be R.cond(conditions, default)?
Niloy Mondal
@niloy
Oct 23 2015 11:26
Thats why one should always put a R.T case at the end.
Denis Stoyanov
@xgrommx
Oct 23 2015 11:36
how is different between http://ramdajs.com/0.18.0/docs/#when and ifElse?
Niloy Mondal
@niloy
Oct 23 2015 11:38
when is basically ifElse(R.__, R.__, R.identity)
Raine Virta
@raine
Oct 23 2015 11:38
when looks like ifElse(__, __, identity)
Niloy Mondal
@niloy
Oct 23 2015 11:38
haha
Denis Stoyanov
@xgrommx
Oct 23 2015 11:48
Can I use something like pattern matching in http://ramdajs.com/0.18.0/docs/#cond
var fn = R.cond([
  [[R.head, R.tail],   R.always('List')],
]);

fn([1,2,3,4]);
Raine Virta
@raine
Oct 23 2015 11:50
no
but it could work with some pattern matching library?
Denis Stoyanov
@xgrommx
Oct 23 2015 11:51
Will be something in future?)
Niloy Mondal
@niloy
Oct 23 2015 11:52
var fn = R.cond([
  [Array.isArray,   R.always('List')],
]);

fn([1,2,3,4]);
Denis Stoyanov
@xgrommx
Oct 23 2015 11:53
no this isn't what I want
Ricardo Pallas
@RPallas92
Oct 23 2015 12:03
check this plaid/sanctuary#12
and this ramda/ramda#797
Denis Stoyanov
@xgrommx
Oct 23 2015 12:14
:(
Viktor Fröberg
@vikfroberg
Oct 23 2015 12:30
Is there a reason why mapIndexed doesn’t exist?
Viktor Fröberg
@vikfroberg
Oct 23 2015 12:32
Intresting! @raine
Denis Stoyanov
@xgrommx
Oct 23 2015 16:22
How can I transform this to Ramda? arr => arr[0].timeStamp < arr1.timeStamp
boxofrox
@boxofrox
Oct 23 2015 17:13
is that supposed to be arr[1].timeStamp?
Raine Virta
@raine
Oct 23 2015 17:15
R.apply(R.lt, R.map(R.prop('ts'), [{"ts": 1}, {"ts": 2}]))
R.pipe(R.map(R.prop('ts')), R.apply(R.lt))
Denis Stoyanov
@xgrommx
Oct 23 2015 17:17
thanks!
Raine Virta
@raine
Oct 23 2015 18:32
_curryN is a lot of work to understand
Raine Virta
@raine
Oct 23 2015 18:57
why does nAry use call and list arguments explicitly and _arity uses apply with arguments?
Tobias Pflug
@gilligan
Oct 23 2015 20:08
Evening
I am a bit curious about the mixture of jshint and jscs - i would have suggested to scrap both in favor of eslint? ;-)
David Chambers
@davidchambers
Oct 23 2015 20:14

@raine, this is the key line in the description of R.nAry:

Any extraneous parameters will not be passed to the supplied function.

Scott Sauyet
@CrossEye
Oct 23 2015 20:15
@raine: arity reports correct function length, but allows user to pass more arguments along. nAry does not pass any extras.
@gilligan: might be willing. JSHint seemed to be state of the art two-and-a-half years ago. Someone suggested JSCS, and I was willing. If there's something better, I'd be for it.
Tobias Pflug
@gilligan
Oct 23 2015 20:18
@CrossEye eslint has developed way way beyond jshint. I only really realized after one of the contributors joined my team at work ;-)
@CrossEye if there is interest i might be interested in working on a PR to switch to eslint
David Chambers
@davidchambers
Oct 23 2015 20:20
Can eslint really replace JSCS? JSCS is extremely configurable.
Tobias Pflug
@gilligan
Oct 23 2015 20:21
eslint is very configurable indeed and has a great plugin architecture if there you really need to go beyond its default capabilities
David Chambers
@davidchambers
Oct 23 2015 20:21
See maximumLineLength, for example.
Tobias Pflug
@gilligan
Oct 23 2015 20:21
eh, yes of course
;-)
and those are only the built-in ones
Scott Sauyet
@CrossEye
Oct 23 2015 20:22
It sounds like it might be a fair bit of work. If so, I would suggest raising an issue first to discuss the reasons for it and to get feedback before committing to much wiry.
Tobias Pflug
@gilligan
Oct 23 2015 20:22
sure
hm, will look at the current config and think about it and might just open an issue to make some suggestions then
Tobias Pflug
@gilligan
Oct 23 2015 20:29
Even after only briefly looking at the current setup I think jshint could probably be removed because whatever jshint can do jscs should probably be able to do
David Chambers
@davidchambers
Oct 23 2015 20:30
I don't think so. JSCS is just a style checker: it doesn't check for unreferenced identifiers and other such things.
Tobias Pflug
@gilligan
Oct 23 2015 20:34
ah, strictly only style ? ok. eslint does both
Raine Virta
@raine
Oct 23 2015 20:35
eslint is pretty cool
Scott Sauyet
@CrossEye
Oct 23 2015 20:35
ESLint does look good.
Raine Virta
@raine
Oct 23 2015 20:36
https://github.com/mantoni/eslint_d.js this enables lightning fast linting in vim (which has poor support for async)
Tobias Pflug
@gilligan
Oct 23 2015 20:38
I use neomake for async linting in neovim
Raine Virta
@raine
Oct 23 2015 20:38
i'm not in the neovim boat yet
Tobias Pflug
@gilligan
Oct 23 2015 20:38
i am actually planning to do a ramda-eslint plugin with some neat rules
boxofrox
@boxofrox
Oct 23 2015 20:39
i need to find time to switch my .vimrc to neovim.
Tobias Pflug
@gilligan
Oct 23 2015 20:39
things like if you use R.filter(R.complement(f), xs) it will suggest to use R.reject instead
David Chambers
@davidchambers
Oct 23 2015 20:39
Oh, that would be terrific!
I was thinking of doing something like that but didn't realize I could do so by writing eslint plugins.
Tobias Pflug
@gilligan
Oct 23 2015 20:40
and perfectly possible with eslint
Conner Bryan
@cab
Oct 23 2015 20:40
thatd be awesome, kind of like how intellij is for scala
Conner Bryan
@cab
Oct 23 2015 20:40
what intellij does*
since you get the an estree compatible AST plus more there is quite a lot you can do
@boxofrox you don't really need to change anything in your vimrc to switch to neovim
boxofrox
@boxofrox
Oct 23 2015 20:47
i'll give neovim a try this weekend then
Tobias Pflug
@gilligan
Oct 23 2015 20:47
@davidchambers @raine and while i am suggesting things that would have a lot of impact - I am thinking jsverify would be a great match for ramda ;-)
David Chambers
@davidchambers
Oct 23 2015 20:48
I agree.
Tobias Pflug
@gilligan
Oct 23 2015 20:48
looking at test/lenses.js
Raine Virta
@raine
Oct 23 2015 20:48
i would like to learn more about how property based testing could be applied in "real world"
Tobias Pflug
@gilligan
Oct 23 2015 20:49
i'd rather have seperate tests for individual lenses and have lens laws as properties tested for each lens
just started a PR to add lensPath (analogous to lensProp) and i don't really want to fiddle it into test/lenses.js
@raine yeah i tried exactly that some time ago when I added jsverify tests to the code base at work
@raine it did not make sense everywhere but in various cases i could remove a lot of laborious/boring tests and replace them with a single property based test
@raine sometimes adding a single classic unit test in order to make a certain behavior more explicit
I also found bugs in the process
Keith Nicholas
@keithn
Oct 23 2015 21:22
Hi all, just getting started with ramda, and wrote good ol fizzbuzz, I have the code posted on codereview if anyone can offer me any feedback about my usage of ramda and whether I can do it any better. http://codereview.stackexchange.com/questions/108449/fizzbuzz-in-javascript-using-ramda
Eric Gjertsen
@ericgj
Oct 23 2015 21:23
i would like to learn more about how property based testing could be applied in "real world"
++++ !!
Raine Virta
@raine
Oct 23 2015 21:36
maybe repeat should work with strings?
boxofrox
@boxofrox
Oct 23 2015 21:37
I've settled with compose(join(''), repeat)
Raine Virta
@raine
Oct 23 2015 21:38
why settle though
boxofrox
@boxofrox
Oct 23 2015 21:39
cause I'd have to give up creating an array of strings with repeat.
Raine Virta
@raine
Oct 23 2015 21:39
yep
Jethro Larson
@jethrolarson
Oct 23 2015 21:41
@keithn that's a good first start. I don't have a better approach that immediately comes to mind.
Raine Virta
@raine
Oct 23 2015 21:45
@keithn
var divisibleBy = R.pipe(R.modulo, R.equals(0))
looks like the fizzbuzz function's output should maybe be joined by \n?
Jethro Larson
@jethrolarson
Oct 23 2015 21:48
I'm definitely impressed with R.cond and point-free used on first try :)
boxofrox
@boxofrox
Oct 23 2015 21:51
Don't need the R.flip like @raine mentioned. About all I could do is make it look prettier. https://tonicdev.com/boxofrox/fizzbuzz-code-review-ramda
Jethro Larson
@jethrolarson
Oct 23 2015 22:03
whoa. tonicdev is awesome
boxofrox
@boxofrox
Oct 23 2015 22:09
inorite! :smile:
Jethro Larson
@jethrolarson
Oct 23 2015 22:10
I might try that for my live coding talk
Being able to mix in rich text, images, and code all at once. <3
boxofrox
@boxofrox
Oct 23 2015 22:12
and the context sensitive console is pretty sweet.
Jethro Larson
@jethrolarson
Oct 23 2015 22:13
AND babel
boxofrox
@boxofrox
Oct 23 2015 22:14
most of babel. i don't think it does string interpolation unless your browser supports it.
Jethro Larson
@jethrolarson
Oct 23 2015 22:15
easy to sacrifice. I really just need basic destructuring and arrows to be happy
Scott Sauyet
@CrossEye
Oct 23 2015 22:15
And written (at least in part) by Ramda contributor @tolmasky.
Jethro Larson
@jethrolarson
Oct 23 2015 22:16
I may want to have his children :P
Scott Sauyet
@CrossEye
Oct 23 2015 22:25
@boxofrox: your second version is not using the divisible function you supply. That's probably good, because I think this function (the same one @raine mentioned above) is missing a flip.
boxofrox
@boxofrox
Oct 23 2015 22:28
Ack!
boxofrox
@boxofrox
Oct 23 2015 22:36
Fixed. Dunno why I thought flip wasn't needed. Probably meant curry... compose used to be curried, yea?
Jethro Larson
@jethrolarson
Oct 23 2015 22:36
I was hoping the text nodes would be markdown :(
Jethro Larson
@jethrolarson
Oct 23 2015 22:39
voted