These are chat archives for ramda/ramda

17th
Oct 2015
boxofrox
@boxofrox
Oct 17 2015 02:21
@scott-christopher thanks for the clarification on ap.
boxofrox
@boxofrox
Oct 17 2015 05:45
@raine trying out replem for the first time. nice work.
Martin Algesten
@algesten
Oct 17 2015 07:03
can this be made point free?
pad = (s) -> if s.length < 4 then pad("0#{s}") else s
it made me think about recursion in general – is that a done thing? invoker on global or how would it work?
Raine Virta
@raine
Oct 17 2015 07:07
point free recursion, hmm
boxofrox
@boxofrox
Oct 17 2015 07:09

don't need the recursion in this case. not sure how to keep it if you did.

pad = R.converge(R.concat, [R.pipe(R.prop('length'), R.negate, R.add(4), R.max(0), R.repeat('0'), R.join('')), R.identity]);

... i think.

Martin Algesten
@algesten
Oct 17 2015 07:11
@boxofrox thanks! ... question is whether this alternative is clearer :)
boxofrox
@boxofrox
Oct 17 2015 07:11
i'd stick with your version.
oops, forgot to R.join and v0.18.0 R.converge takes an array of functions as second argument.
boxofrox
@boxofrox
Oct 17 2015 07:16
and need length - 4, so R.negate with R.add(4). that works.
really lovin replem @raine
Raine Virta
@raine
Oct 17 2015 07:17
@boxofrox cool. i'm actually just fixing a bug in it
Martin Algesten
@algesten
Oct 17 2015 07:21
yes @raine it's very much part of my everyday now. thank you! ... one thing i noticed, not sure whether it's just my setup (mac os x, plain terminal app). whenever there's an exception, i can't use the arrow keys to navigate the repl history anymore.
boxofrox
@boxofrox
Oct 17 2015 07:22
@algesten my approach to point free is more focused on code reuse. define pad as a curried function, then use it point-free later. A la
pad = R.curry((n, c, s) -> if n > s.length then pad("#{c}#{s}") else s);

# Sometime later

printId = R.pipe(pad(9, '0'), console.log.bind(console));

printId('1234');
Martin Algesten
@algesten
Oct 17 2015 07:23
@boxofrox yes. that's a nice solution. i tend to leave functions at their most simple until i find i want to reuse. typically i only reuse within the context of a project.
boxofrox
@boxofrox
Oct 17 2015 07:26
I just had an exception in replem, but was able to use arrow keys to navigate the repl history. Arch Linux with tmux/zsh.
Raine Virta
@raine
Oct 17 2015 07:27
@algesten gkz/LiveScript#733 seem familiar?
Martin Algesten
@algesten
Oct 17 2015 07:31
@raine yes. exactly that.
Raine Virta
@raine
Oct 17 2015 07:48
can we make ramda-string or something
it would be nice to have contains, endsWithetc. readily available
Niloy Mondal
@niloy
Oct 17 2015 07:54
Great idea
Raine Virta
@raine
Oct 17 2015 09:06
the asymmetry of propEq and propSatisfies is making me a bit uneasy
Raine Virta
@raine
Oct 17 2015 09:23
when you have both propEq propSatisfies next to each other, it'd be more readable if they both took property name first
James Salamon
@lorezzed
Oct 17 2015 10:26

Hi folks,

I'd appreciate some advice on getting values inside an object. Here's what I got so far

// our object
    var stream = {
        fromUser: { username: 'ram' },
        text: 'da'
    };

    // imperative way
    var _username = stream.fromUser.username;
    var _message = stream.text;
    console.log('%s: %s', _username, _message); // => 'ram: da'

    // fx way (need advice on this)
    var username = R.path(['fromUser', 'username']);
    var message = R.prop('text');        
    log(R.join(': ', [username(stream), message(stream)])); // => 'ram: da'

    // fx helper. Could we use this like `R.map(log, results)` to improve readability?
    function log(x) { console.log(x); return x; };
James Salamon
@lorezzed
Oct 17 2015 10:33
also taking suggestions on any recommended books on functional programming :)
Hardy Jones
@joneshf
Oct 17 2015 10:49
What advice are you looking for?
@lorezzed
James Salamon
@lorezzed
Oct 17 2015 10:50
i thought there might be a better way of getting the same results
atm it looking up stream twice, one for each value
maybe theres a way to map/compose to make it a little tidier?
Aldwin Vlasblom
@Avaq
Oct 17 2015 10:57

@lorezzed The fx helper you wrote only exists to have a function (console.log) perform its side-effect, and then return the original value without modifying it. There's a helper in Ramda called R.tap for exactly those cases: var log = R.tap(console.log);

Your functional way should aim to build up a function, rather than a value. You can compose, converge, pipe and useWith to combine functions into other functions:

var log = R.tap(console.log);
var getUsername = R.path(['fromUser', 'username']);
var getMessage = R.prop('text');
var getPair = R.converge(R.unapply(R.join(': ')), [getUsername, getMessage]);
var program = R.pipe(
  getPair,
  log
);

//Finally execute
program(stream);

For learning some functional programming I'd recommend

Aldwin Vlasblom
@Avaq
Oct 17 2015 11:02
Here's the code in the REPL. :)
James Salamon
@lorezzed
Oct 17 2015 11:08
awesome thanks, just what im after!
<3 it
Aldwin Vlasblom
@Avaq
Oct 17 2015 11:13
Awesome. Glad to help. Functional programming is a lot of fun! Hope I helped you underway. Personally I also learned a lot from just lurking in this channel. Once you're dealing with Monads and stuff, I recommend also joining the fantasy-land and sanctuary rooms. :D
Raine Virta
@raine
Oct 17 2015 11:37
any clue about this? @davidchambers
$ replem ramda@0.15:R
Installed into REPL context:
 - ramda@0.15.1 as R
> R.invoker(0, 'toString')(function() {})
'function () {}'
$ replem ramda@0.16:R
Installed into REPL context:
 - ramda@0.16.0 as R
> R.invoker(0, 'toString')(function() {})
TypeError: function () {} does not have a method named "toString"
    at /Users/rainevi/.replem/node_modules/ramda/dist/ramda.js:7113:19
nothing apparent in 0.16 upgrade guide
Aldwin Vlasblom
@Avaq
Oct 17 2015 21:56
I think it'd be cool to process streams with transducers, I don't fully understand Ramda's transduce though. Does it provide a means to create a generic transducer? If it does I'd probably prefer using Ramda over transducers, transducers-js, transducers.js or underarm.
But all of their readme's are easier to understand.
Aldwin Vlasblom
@Avaq
Oct 17 2015 22:02
Oh, is a composition of typical Ramda iterators enough to "create a generic reducer" because they can "act as transducers"? So transduce is just a means to implement specific types of into and such?
Aldwin Vlasblom
@Avaq
Oct 17 2015 22:40
Darn. The transduce-stream package is outdated and doesn't seem to support object streams. :\