These are chat archives for ramda/ramda

11th
Jun 2016
LeonineKing1199
@LeonineKing1199
Jun 11 2016 02:28
Okay, I'm going to finish my little blog rant about the Mostly Adequate stuff. I totally read it wrong. I re-read it again with fresh eyes and you guys, holy poop, I think this is the first time that I feel like I finally understand functors and how they become monads. There's never been a better feeling. It's literally just classes which is kind of hilarious but also super awesome. I can rest easy now
Vladimir Kapustin
@kapooostin
Jun 11 2016 05:08
It started more as an exercise to get as much point-free functions as possible, but now I’m curios is it practical to build such huge functions or it is better to extract different parts of it into separate functions:
var addImgPath = R.compose(
  R.assocPath( [ 'options', 'imgPath' ] ),
  R.converge(
    R.useWith(
      R.path,
      [
        R.ifElse(
          R.equals( 'prod' ),
          R.always( [ 'config', 'bankImgPath' ] ),
          R.flip( R.append )( [ 'options', 'imgPath' ] )
        ),
        R.identity
      ]
    ),
    [
      R.path( [ 'app-state', 'mode' ] ),
      R.identity
    ]
  )
);
Gleb Bahmutov
@bahmutov
Jun 11 2016 05:37
yeah, definitely unreadable. I would not be able to understand this style, unless I wrote everything this way, and that just not going to happen.
Vladimir Kapustin
@kapooostin
Jun 11 2016 06:48
For me it is just as readable as are readable some complex regular expressions.
Vladimir Kapustin
@kapooostin
Jun 11 2016 06:55
So maybe the question is: what is the common practice? How many nested ramda functions is too much?
James Forbes
@JAForbes
Jun 11 2016 07:29
@kapooostin I don't think its the nesting necessarily, its the complexity of the component functions, useWith and converge are probably harder to follow than some nested pipes and maps
Baqer Mamouri
@bmamouri
Jun 11 2016 07:40

Hey guys,

Do we have a function in ramda that accept a function and perform it on the input? Here is what I am trying to do:

const specs = ['Air Conditioning', 'Built-In-Wardrobes', 'Ensuite', 
         'Fenced Back Yard', 'Grey Water System', 
         'Internal Access via Garage', 'Outdoor Entertainment Area', 
         'Rain water tanks', 'Remote Control Garaging', 
         'Security Screens']

R.ifElse(
  R.is(String), 
  R.identity,
  R.pipe(
    R.map(x => `<li>${x}</li>`),
    // How to enclose the output in <ul><ul>
  )
)(specs)

specs can be a string or a list. If it is a list I want to convert it to Unordered List.

I am looking for something like R.apply that can be called on a function with only one input

R.append and R.prepend are close too. But not quite:

const specs = ['Air Conditioning', 'Built-In-Wardrobes', 'Ensuite', 
         'Fenced Back Yard', 'Grey Water System', 
         'Internal Access via Garage', 'Outdoor Entertainment Area', 
         'Rain water tanks', 'Remote Control Garaging', 
         'Security Screens']

R.ifElse(
  R.is(String), 
  R.identity,
  R.pipe(
    R.append(‘</ul>'),
    R.prepend('<ul>'),
    R.map(x => `<li>${x}</li>`),
  )
)(specs)

The problem is the output is not quite right:

["<li><ul></li>", "<li>Air Conditioning</li>", "<li>Built-In-Wardrobes</li>", "<li>Ensuite</li>", "<li>Fenced Back Yard</li>", "<li>Grey Water System</li>", "<li>Internal Access via Garage</li>", "<li>Outdoor Entertainment Area</li>", "<li>Rain water tanks</li>", "<li>Remote Control Garaging</li>", "<li>Security Screens</li>", "<li></ul></li>”]
James Forbes
@JAForbes
Jun 11 2016 08:51
@bmamouri just put your append,prepend after the map

I have a similar function I use with mithril/snabbdom to make unordered lists out of arrays of virtual elements or strings.

var M = R.curryN(2, m)

var ul = R.compose(
    M("ul.list-inline"),
    R.map(
        M('li')
    )
)

Which translates to:

const input = [m('strong', 'Strong'),  m('i', 'Italicised'), 'simple text']
ul(input)

// which outputs
m('ul.list-inline'
      ,m('li', m('strong', 'Strong')))
      , m('li',m('i', 'Italicised'))
      , m('li', 'simple text' )
)

And that would evaluate to the correct HTML when rendered.

So if you are just dealing with strings. Maybe make a tag function that generates html for a given tag, and then you can use the same sort of composition. But your append/prepend thing works well as well.

Hey everyone, is there a function that is the equivalent output of R.values(R.groupBy(...)) built into ramda?

Kind of like http://ramdajs.com/docs/#splitWhen but for multiple sub lists.

James Forbes
@JAForbes
Jun 11 2016 09:03
Here is a bootstrap table being generated in much the same way.
var thead = R.compose(
        M('thead'),
            M('tr'),
                R.map(
                    R.pipe(capitalize, M('th'))
                )
    )

var tbody = R.compose(
        M('tbody'),
        R.map(M('tr')),
        R.map(
            R.map(
                M('td')
            )
        )
    )

// (headings, rows) -> table
var table = R.useWith(
        M("table.table table-striped"), [
            thead,
            tbody
        ]
    )
Baqer Mamouri
@bmamouri
Jun 11 2016 10:56
Thank you @JAForbes your anwers help me a lot. Greatly appreciate it
Vladimir Kapustin
@kapooostin
Jun 11 2016 20:22
@JAForbes Maybe. I got a grasp of them once I found a usecase for these functions.