These are chat archives for ramda/ramda

7th
May 2017
Julio Borja Barra
@juboba
May 07 2017 14:59

sup folks!
I'm on my way of finding point-free solution to this:

var obj = {
  a: 1,
  g: {
    c: false
  },
  b: {
    c: true
  },
  d: {
    c: true
  }
}

const howManyWithC = o => length(
  keys(
    pickBy(
      equals(true),
      mapObjIndexed(
        (_, key) => path([key, 'c'], o),
        o
      )
    )
  )
)

console.log(howManyWithC(obj) // 2

This gets me the length of keys that have a subkey named 'c' and it's value === true.
Any ideas?

the _ I'm using is just a placeholder to say "I don't care about the value", not the R.__ placeholder
Rónán
@ronanyeah
May 07 2017 15:08
is this it?
const howManyWithC =
  pipe(
    toPairs,
    map(last),
    filter(propSatisfies(equals(true), 'c')),
    length
  )
James Forbes
@JAForbes
May 07 2017 15:09
how bout

pipe(
  values
  ,filter( prop('c') )
  ,length
)
Ah very similar @ronanyeah :D
Julio Borja Barra
@juboba
May 07 2017 15:09
oh
Rónán
@ronanyeah
May 07 2017 15:09
@JAForbes yours is better :)
Julio Borja Barra
@juboba
May 07 2017 15:09
right, I was just complicating myself
James Forbes
@JAForbes
May 07 2017 15:09
Yours is more precise :D @ronanyeah
Julio Borja Barra
@juboba
May 07 2017 15:09
thanks guys
James Forbes
@JAForbes
May 07 2017 15:09
:+1: @juboba
Julio Borja Barra
@juboba
May 07 2017 15:10
although I will use propEq('c', true) because I need it to be true and not some object or anything else
James Forbes
@JAForbes
May 07 2017 15:11
@juboba @ronanyeah 's won't trip up on truthy/falsey like mine will, so maybe use that filter
propEq! :tada:
Rónán
@ronanyeah
May 07 2017 15:11
@juboba yeah use propEq and values :+1:
Julio Borja Barra
@juboba
May 07 2017 15:11
right
<3 R
:P
Philipp Wille
@Yord
May 07 2017 19:46
Can somebody help me with the following problem with lenses:
const state = {
  id: 1,
  data: {
    1: 'one',
    2: 'two'
  }
}

const id = lensProp('id')
const data = lensProp('data')
const entry = id => compose(data, lensProp(id))

const result = view(entry(view(id, state)), state)
I want to get rid of the duplicate "state" in result
(The result of course should be one)
Denis Stoyanov
@xgrommx
May 07 2017 20:02
@Yord
const state = {
  id: 1,
  data: {
    1: 'one',
    2: 'two'
  }
}

const id = lensProp('id')
const data = lensProp('data')
const entry = id => compose(data, lensProp(id))
const fn = state => entry(view(id, state))

ap(flip(view), fn)(state)
@Yord ap(flip(view), compose(entry, view(id)))(state)
Philipp Wille
@Yord
May 07 2017 20:25
@xgrommx Oh wow thanks. That helps for now!
Philipp Wille
@Yord
May 07 2017 20:49
This actually helped me understand ap for the first time :) Thank you!