These are chat archives for ramda/ramda

21st
May 2017
Jason Shin
@JasonShin
May 21 2017 01:24
guys Ramda noob here
const R = require('ramda')
const Future = require('fluture')
const fetch = require('node-fetch')

const fetchYesNo = () => {
  // return fetch('https://yesno.wtf/api')
  return Future.node((done) => {
    fetch('https://yesno.wtf/api')
      .then(res => res.json())
      .then(done)
  }).chain(R.identity)
}


const result = R.compose(
  R.prop('answer'),
  R.tap(console.log),
  fetchYesNo
)

console.log(result)
compose doesn't fork
fetchYesNo
do you know why?
Gabe Johnson
@gabejohnson
May 21 2017 01:41
@JasonShin you don't appear to be calling fork anywhere
Gabe Johnson
@gabejohnson
May 21 2017 01:48
Is there a reason you're using node instead of encaseP?
Jason Shin
@JasonShin
May 21 2017 03:15
@gabejohnson ah right.. I was just following some tutorials
I'm still getting my head around about Fluture + Ramda atm
let me give that a try
Gabe Johnson
@gabejohnson
May 21 2017 03:18
Good luck!
Jason Shin
@JasonShin
May 21 2017 03:18
thanks
Jason Shin
@JasonShin
May 21 2017 11:42
hey guys
Ramda questions
formatJson (attrs) {
    const arrayOrObject = R.anyPass([
      R.is(Array), R.is(Object)
    ])
    const stringify = R.ifElse(
      arrayOrObject,
      R.toString,
      R.identity
    )
    const mapList = R.map(stringify)
    return mapList(attrs)
  },

I have above function (which I don't think it's declarative.)
It basically takes a parameter called attrs

attrs = {
  test: 123,
  test1: 'test',
  test2: { name: 'jason', name2: 'shin'}
}

and convert any field with JSON value to have stringified JSON value.

How would you refactor it so that it reads right -> left like
R.compose?
Tom Harding
@i-am-tom
May 21 2017 11:45
Is JSON.stringify what you want?
Jason Shin
@JasonShin
May 21 2017 11:45
yeah
but only on entries with actual JSON or Array value
Tom Harding
@i-am-tom
May 21 2017 11:46
I’m not sure I understand- it looks like you’re converting all non-array-or-obj to strings and ignoring everything else
Jason Shin
@JasonShin
May 21 2017 11:47
yeah
that's exactly right
Tom Harding
@i-am-tom
May 21 2017 11:47
Huh. Ok, well
Jason Shin
@JasonShin
May 21 2017 11:47
@i-am-tom oh actually
it's opposite
I'm trying to convert all array or object in a List
Tom Harding
@i-am-tom
May 21 2017 11:47
Aha, beg your pardon
Jason Shin
@JasonShin
May 21 2017 11:48
to String
while ignoring everything else
Tom Harding
@i-am-tom
May 21 2017 11:49
const formatJSON = R.map(
  x => typeof x === ‘object’
        ? R.toString(x)
        : x
)
There’s definitely such a thing as too much Ramda, hah
Jason Shin
@JasonShin
May 21 2017 11:50
right
Denis Stoyanov
@xgrommx
May 21 2017 11:50
IfElse + is
Jason Shin
@JasonShin
May 21 2017 11:51
R.map(
x => R.is(Array) || R.is(Object) ? R.toString : x
)
lol so much shorter
thanks
Tom Harding
@i-am-tom
May 21 2017 11:51
nw :) I believe typeof x === ‘object’ shaves a few more chars off, too
> typeof []
'object'
> typeof 'hello'
'string'
> typeof 1
'number'
> typeof {}
‘object'
Jason Shin
@JasonShin
May 21 2017 11:52
right
Denis Stoyanov
@xgrommx
May 21 2017 11:52
is(Object, x)
Tom Harding
@i-am-tom
May 21 2017 11:52
:)
Jason Shin
@JasonShin
May 21 2017 11:53
=)
Denis Stoyanov
@xgrommx
May 21 2017 11:53
Sorry I'm from phone
Jason Shin
@JasonShin
May 21 2017 11:54
well I feel like I was too excited about Ramda which resulted in bloated Ramda code
Tom Harding
@i-am-tom
May 21 2017 11:54
Hah ^_^ Plenty to get excited about, but always favour simplicity
Jason Shin
@JasonShin
May 21 2017 11:55
yeah
simplicity > ramda
Tom Harding
@i-am-tom
May 21 2017 11:56
Ramda helps an awful lot in many situations, though!
Denis Stoyanov
@xgrommx
May 21 2017 12:03
Sometimes lambda is more readable and preferable than point free
Brian McKenna
@puffnfresh
May 21 2017 12:03
sometimes
:)
Jason Shin
@JasonShin
May 21 2017 12:22
I'm 95% done with getting rid of lodash
I will probably still going to use lodash-debounce
but yarn add lodash-debounce explicitly
Rick Medina
@rickmed
May 21 2017 17:07
@JasonShin :tada:
Jason Shin
@JasonShin
May 21 2017 23:02
lol

Guys, Ramda noob question.

R.compose(
  takeTwoValuesAndCalc,
  ajaxCall2,
  ajaxCall1,
)

I have two Futures called ajaxCall1 and ajaxCall2, how do you call two Futures and pass values to takeTwoValuesAndCalc?

takeTwoValuesAndCalc (ajaxCall1Value, ajaxCall2Value)