These are chat archives for ramda/ramda

17th
Sep 2017
Jason Shin
@JasonShin
Sep 17 2017 04:53
Hey guys
const setup = () => {
  return fantasy.Future((rej: Function, res: Function) => {
    try {
      /**
       * Load environment variables from .env file, where API keys and passwords are configured.
       */
      dotenv.config({ path: path.join(__dirname, '/../../.env') });
      return res(dotenv)
    } catch (e) {
      console.error('Failed to setup config! ', e)
      return rej(e)
    }
  })
}
how do you do that in Fluture?
Dmitry
@zerobias
Sep 17 2017 04:58
const setup = Future
  .try( () => dotenv.config({ path: path.join(__dirname, '/../../.env') }) )
  .mapRej( tap( e => console.error('Failed to setup config! ', e) ) )
Dmitry
@zerobias
Sep 17 2017 05:04
@alexandrethsilva better switch to fluture ramda/ramda-fantasy#157
Joe Egan
@joeegan
Sep 17 2017 12:16
Hi folks,
Can I do without the n => - I'm a little hazy on __?
const colorBasedOffHash = hash =>
  compose(
    map(n => parseInt(n, 16)), 
    take(3),
    splitEvery(2)
  )(hash)
Philipp Wille
@Yord
Sep 17 2017 12:18
@joeegan Hey, you could use flip:
flip(parseInt)(16)
(or __ if you curry):
curry(parseInt)(__, 16)
Joe Egan
@joeegan
Sep 17 2017 12:23
@Yord Hello again! I'm getting a single arr item returned with those, rather than the array: https://goo.gl/DqazFJ
@Yord I see how flip works though - as it's not curried - that's great thanks
Philipp Wille
@Yord
Sep 17 2017 12:26
Sry was a little bit in a hurry: These were meant to replace n => parseInt(n, 16) (so they have to be wrapped inside map)
Joe Egan
@joeegan
Sep 17 2017 12:27
No worries - i did try map(flip(parseInt(16))), looks like I'm close...
Philipp Wille
@Yord
Sep 17 2017 12:28
ah I see, you provided 16 as an argument before flipping. You have to flip first and then specify the first argument: map(flip(parseInt(16))) => map(flip(parseInt)(16))
Joe Egan
@joeegan
Sep 17 2017 12:32
My mistake, thanks again - this seems to be a good lesson in handling non-curried functions
Joe Egan
@joeegan
Sep 17 2017 13:33
Is there a similar way to avoid the arrow here perhaps?
const row = times(
  n => multiply(inc(n), CELL_SIZE),
  CELLS_PER_ROW
)
James Forbes
@JAForbes
Sep 17 2017 13:39
pipe( inc, multiply(CELL_SIZE) )
Adam Szaraniec
@mimol91
Sep 17 2017 13:41
R.range(0, CELL_SIZE).map(pipe(R.inc,R.multiply(CELLS_PER_ROW)))
Joe Egan
@joeegan
Sep 17 2017 13:41
@JAForbes :+1: Thanks!
@mimol91 Thanks - I've been finding times to be less verbose than range + map
(when I'm going from 0)
Adam Szaraniec
@mimol91
Sep 17 2017 13:45
I was trying to find an function that allows to create range with given step, but I think you need to create it by your own. I think it will be more generic
Joe Egan
@joeegan
Sep 17 2017 13:45
@mimol91 Ah I see
Adam Szaraniec
@mimol91
Sep 17 2017 13:46
Probably like
const rangeWithStep = R.curry((start, stop, step) => 
    R.range(start, stop).map(pipe(R.multiply(step))))
but I m FP newbie also :)
and It does not work with negative numbers
Joe Egan
@joeegan
Sep 17 2017 21:46
Hi folks, any ideas on removing the arr => ... (arr) in removeMidRepeated?
 const indexToRemove = compose(
  flip(divide)(2),
  length,
 )

const removeMidRepeated = arr => compose(
  addIndex(reject)(
    flip(equals(indexToRemove(arr)))
  )
)(arr)
Kurt Milam
@kurtmilam
Sep 17 2017 22:24
@joeegan try const removeMidRepeated = chain(drop, indexToRemove)
Unless I'm misreading, the compose, flip and addIndex in the second function aren't doing anything, btw.
Kurt Milam
@kurtmilam
Sep 17 2017 22:47
This is probably how I'd write it. Am on a mobile, so please excuse typos:
const divide_ = flip( divide )
const removeMidRepeated =
  chain( drop )
       ( o( divide_( 2 ) )
          ( length )
       )