Ramda Stack Example

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
<button onClick="doIt()">
Do it again
</button>

JavaScript

const fullName = R.pipe(
    R.props([ 'firstName', 'middleName', 'lastName']),
    R.filter(R.identity),
    R.join(' ')
)

const takeFullName = function(fullNameProp) {
 return fullName(fullNameProp)
}

const commenters = R.pipe(
    R.map(R.pipe(R.prop('author'), takeFullName)),
    R.uniq,
    R.sortBy(R.identity)
)

let comments = [
  {
    author: { firstName: 'Thai', lastName: 'P' },
    text: 'I like functional programming!'
  },
  {
    author: {
      firstName: 'A',
      middleName: 'random',
      lastName: 'commenter'
    },
    text: 'Why?'
  },
  {
    author: { firstName: 'Thai', lastName: 'P' },
    text: 'Where should we begin?'
  }
]

comments = [ ...comments, {
  author: null,
  text: 'How about referential transparency?'
} ]

const doIt = _ => commenters(comments)

console.log(commenters(comments));