title: Refactor R.filter and R.map to just R.reduce in pointfree style
body: <p>I've started learning <a href="http://ramdajs.com/docs" rel="nofollow">Ramda.js</a> and functional programming and am very interested in functional composition using the pointfree style of programming, but I am having difficulty getting my head around some of it and I'm hoping someone can help illustrate:</p>
  
  <p>Suppose I have a list of people - I want to only get the people between an inclusive age range of 13-19 (teenagers). Then, I want to map each person to either the return value of the person's <code>getName()</code> method (if it exists), else their <code>name</code> property. Then, I want to call <code>.toUpperCase()</code> on the names.</p>
  
  <p>If I were using regular JS prototype methods, I wouldn't use <code>Array.prototype.filter</code> to get the teenage users and then <code>Array.prototype.map</code>. For performance reasons, I'd use <code>Array.prototype.reduce</code>, the body of which would be guarded by a conditional that checks if each iterated item meets the criteria for a teenager. This way, I'm iterating one less time. <a href="http://elijahmanor.com/reducing-filter-and-map-down-to-reduce/" rel="nofollow">Elijah Manor has an article about this on his blog</a>.</p>
  
  <p>Here's the pointfree Ramda code I've come up with using <code>R.filter</code> and <code>R.map</code> (this works as expected):</p>
  
  <pre><code>var people = [
    { name: 'Bob', gender: 'male', age: 22 },
    { name: 'Jones', gender: 'male', age: 15 },
    { name: 'Alice', gender: 'female', age: 19 },
    { name: 'Carol', gender: 'female', age: 32 },
    { name: 'Odu', gender: 'male', age: 25 },
    { name: 'Fred', gender: 'male', age: 55 },
    { name: 'Nicole', gender: 'female', age: 29 },
    { getName: function() { return 'David' }, gender: 'male', age: 23 }
  ]
  
  var getUpcasedTeenagerNames = R.pipe(
    R.filter(
      R.propSatisfies(R.both(R.lte(13), R.gte(19)), 'age')
    ),
    R.map(
      R.pipe(
        R.ifElse(
          R.propIs(Function, 'getName'),
          R.invoker(0, 'getName'),
          R.prop('name')
        ),
        R.toUpper
      )
    )
  )
  
  getUpcasedTeenagerNames(people) // =&gt; ['JONES', 'ALICE']
  </code></pre>
  
  <p>My question is - how would I re-write the following native version of the above algorithm to use pointfree Ramda.js?</p>
  
  <pre><code>var getUpcasedTeenagerNames = function(people) {
    return people
      .reduce(function(teenagers, person) {
        var age = person.age
        if (age &gt;= 13 &amp;&amp; age &lt;= 19) {
          var name
          if (typeof (name = person.getName) === 'function') {
            name = name()
          } else {
            name = person.name
          }
          teenagers.push(name.toUpperCase())
        }
        return teenagers
      }, [])
  }
  </code></pre>
  
  <p>I've tried doing it with <code>R.scan</code>, looked at using <code>R.reduced</code> and <code>R.when</code> but I'm afraid I might be missing the point a little bit.</p>
  
  <p>For your convenience, I've included this code on the Ramda REPL: <a href="http://goo.gl/6hBi5k" rel="nofollow">http://goo.gl/6hBi5k</a></p>