These are chat archives for ramda/ramda

16th
Jan 2017
James Forbes
@JAForbes
Jan 16 2017 00:34

I do, its all closed source though :( and its kind of too big to work as a gist. I'll think about how I can extract some of out into a library at some point and open source it. @svozza

But its really just the Elm architecture but instead of using StartApp as the only interpreter, you also have something like TestApp or ServerSideRenderApp. There's nothing about that pattern that requires it to only be used client side, I used it server side to write a task queue, but I also use it client side for components. Its not Elm but I pretended it was using https://github.com/paldepind/flyd and https://github.com/JAForbes/sum-type.

why is it an empty object
Scott Christopher
@scott-christopher
Jan 16 2017 02:23
@6ewis Object.create will use the given object argument as the prototype for the created object, rather than direct properties.
And the console.log implemented in the REPL presumably only displays the own enumerable properties.
Lewis
@6ewis
Jan 16 2017 02:32
@scott-christopher i see thanks. apparently using Object.assign with Object.create as an argument does not take into account the prototype of the object
Keith Alexander
@kwijibo
Jan 16 2017 17:25

How would you refactor

R.filter(testX)(xs)

to allow for testX needing to do asynchronous computation?

Keith Alexander
@kwijibo
Jan 16 2017 17:30
I came up with
//testX ::  a -> Future Maybe a
//instead of a -> Boolean
R.pipe(
  R.traverse(Future.of, testConstraint), // Future List Maybe testConstraint
  R.reduce(R.concat),
  R.map(S.maybeToNullable)
)(xs)
but it seems quite a bit more complicated than the original - is there a simpler way?
Brad Compton (he/him)
@Bradcomp
Jan 16 2017 18:16
Would this work?
pipe(
  traverse(Future.of, testConstraint),
  map(S.justs)
);
I know it brings in Sanctuary, but you could conceivably write a justs for whatever Maybe you're using
Keith Alexander
@kwijibo
Jan 16 2017 18:31
@Bradcomp thanks as you can see I was already presuming Sanctuary or equiv functionality, i had missed S.justs
Syaiful Bahri
@syaiful6
Jan 16 2017 18:32
@kwijibo i would have your filter function be like that, i will just change the array passed to it, in other words the results of Future will be passed to it instead.
Keith Alexander
@kwijibo
Jan 16 2017 18:40
@syaiful6 I don't understand how that would work
the difficulty is that you have to asynchronously map the value to a boolean, and include the original value if the boolean is true
Syaiful Bahri
@syaiful6
Jan 16 2017 18:44
for example that your original testX return true if it passed Just to it, they would. R.filter(testX)(xs), if you managed to do the async task and pass that result as xs it will yield same results?
it easy to test simple R.filter(testX) rather than wrap it all on your Future. if you can extract your computation out of you monad then use it instead.
but that my opinion, because i find it easy to test it.
Keith Alexander
@kwijibo
Jan 16 2017 18:48
what do you suggest should be done asynchronously though? it is the testing itself I need to do asynchronously
testX is hitting a web service that will return true or false
eg if you want to convert R.filter(isOdd)([1,2,3,4]) to R.filter(isOddAsync)([1,2,3,4]) ... I can imagine getting a Future of an array of booleans, and then matching up the indexes to the input array of values in order to filter it, but that also seems quite complicated
Syaiful Bahri
@syaiful6
Jan 16 2017 19:01
@kwijibo not like that i mean, leave the original (if any, that not run async), instead do the async task on other function and pass the results as the format the original want.
Brad Compton (he/him)
@Bradcomp
Jan 16 2017 19:02
Also, check out the filter implementations on Sanctuary for other ideas on how to implement filter in terms of the type classes: https://github.com/sanctuary-js/sanctuary-type-classes#filter--applicativeffoldablefmonoidfa--a-booleanfa---fa
Syaiful Bahri
@syaiful6
Jan 16 2017 19:03
:+1:
Brad Compton (he/him)
@Bradcomp
Jan 16 2017 19:03
Although it still assumes an a -> Bolean which is the whole issue.
Syaiful Bahri
@syaiful6
Jan 16 2017 19:05
yes since it use Future, then it will wrapped on future all the time.
Syaiful Bahri
@syaiful6
Jan 16 2017 19:14
i mean like this @kwijibo.
// keep this pure, 
Array Int -> Array Int
oddNumber = R.filter(isOdd)

// here we fetch web service
Array Int -> Future (Array Int)
fetchService = R.traverse(Future.of, doRequest)

// an here we use our pure f
oddNumberAsync = R.compose(R.map(oddNumber), fetchService)
i imagine your original function also that the case, if not then ignore me.