Example #1
0
export default state =>
  map(c => <div key={c.course_code} className='search-list-element'>
    <div className='result-list-coursename'>{`${c.course_code} - ${c.course_name}`}</div>
    <div className='result-list-remove' onClick={() => {
      appState.dispatch({type: 'REMOVE_COURSE', course_code: c.course_code})
    }}>X
    </div>
  </div>, uniqWith(eqBy(prop('course_code')))(state.selectedCourses))
Example #2
0
 store.socratesOnlyMembers((err1, socMembers) => {
   if (err1 || !members) { console.log('avatar updater had problems loading members'); }
   console.log('starting avatar update');
   async.each(R.unionWith(R.eqBy(m => m.id()), members, socMembers), service.updateImage, err2 => {
     if (err2) {
       console.log('avatar updater encountered an error: ' + err2.message);
     }
     console.log('finishing avatar update');
     process.exit();
   });
 });
  const newXs: Array<string> = _.append('one', ss)
  const newXs1: Array<number> = _.prepend(1)(ns)

  const concatxs1: Array<number> = _.concat([ 4, 5, 6 ], [ 1, 2, 3 ])
  const concatxs2: string = _.concat('ABC', 'DEF')

  const cont1: boolean = _.contains('s', ss)

  const dropxs: Array<string> = _.drop(4, ss)
  const dropxs1: string = _.drop(3)(str)
  const dropxs2: Array<string> = _.dropLast(4, ss)
  const dropxs3: string = _.dropLast(3)(str)
  const dropxs4: Array<number> = _.dropLastWhile(x => x <= 3, ns)
  const dropxs5: Array<string> = _.dropRepeats(ss)
  const dropxs6: Array<number> = _.dropRepeatsWith(_.eqBy(Math.abs), ns)
  const dropxs7: Array<number> = _.dropWhile(x => x === 1, ns)

  const findxs:?{[k:string]:number|string} = _.find(_.propEq('a', 2), os)
  const findxs1:?{[k:string]:number|string} = _.find(_.propEq('a', 4))(os)
  const findxs2:?{[k:string]:number|string} = _.findLast(_.propEq('a', 2), os)
  const findxs3:?{[k:string]:number|string} = _.findLast(_.propEq('a', 4))(os)
  const findxs4: number = _.findIndex(_.propEq('a', 2), os)
  const findxs5:number = _.findIndex(_.propEq('a', 4))(os)
  const findxs6:number = _.findLastIndex(_.propEq('a', 2), os)
  const findxs7:number = _.findLastIndex(_.propEq('a', 4))(os)

  const s: Array<number> = filter(x => x > 1, [ 1, 2 ])
  const s1: Array<string> = _.filter(x => x === '2', [ '2', '3' ])
  const s3: {[key: string]: string} = _.filter(x => x === '2', { a:'2', b:'3' })
  const s4 = _.find(x => x === '2', [ '1', '2' ])
const numbers = [ 1.0, 1.1, 1.2, 2.0, 3.0, 2.2 ]
const letters = _.split('', 'abcABCaaaBBc')
// In ramda docs example it's just `Math.floor`
// but we don't want the implicit number -> string
const countB = _.countBy(_.compose(_.toString, Math.floor))(numbers)
const countB1: {[k:string]:number} = _.countBy(_.toLower)(letters)
const diff: Array<number> = _.difference([ 1,2,3,4 ], [ 7,6,5,4,3 ])
//$ExpectError
const diff1: Array<string> = _.difference([ '1', '2' ,'3', '4' ], [ 7, 6, 5, 4, 3 ])

const cmp = (x, y) => x.a === y.a
const l1 = [ { a: 1 }, { a: 2 }, { a: 3 } ]
const l2 = [ { a: 3 }, { a: 4 } ]
const diff2 = _.differenceWith(cmp, l1, l2)

const eqb: boolean = _.eqBy(Math.abs, 5, -5)

const es: boolean = _.equals([ 1, 2, 3 ], [ 1, 2, 3 ])

const _gt: boolean = _.gt(2, 1)
const _lt: boolean = _.lt(2, 1)

const _gte: boolean = _.gte(2, 1)
const _lte: boolean = _.lte(2, 1)

const _max: number = _.max(2, 1)
const _min: number = _.min(2, 1)

const _maxBy: number = _.maxBy(Math.abs)(2, 1)
const _minBy: number = _.minBy(Math.abs, 2, 1)
Example #5
0
  toString,
  addIndex,
  reduceRight,
  eqBy,
  juxt,
  init,
  sum,
  split,
} from 'ramda'

const reduceRightIndexed = addIndex(reduceRight)
const clean = replace(/[^0-9]/g, '')

const mask = [0, 1, 2, 3, 4, -4, -3, -2, -1, 0]

const sameParity = eqBy(modulo(__, 2))
const finalSumReducer = (acc, digit, index, digits) =>
  acc + (sameParity(digits.length - 1, index) ? mask[digits[index]] : 0)

const validate = (cardNumber) => {
  const [withoutLastDigit, lastDigit] = juxt([init, last])(cardNumber)
  const finalSum = reduceRightIndexed(
    finalSumReducer,
    sum(withoutLastDigit),
    split('', withoutLastDigit)
  )
  const rest = 10 - (finalSum % 10)
  return (rest === 10 ? 0 : rest) === parseInt(lastDigit, 10)
}

export default pipe(
Example #6
0
const _ = require('ramda');
const data = [{name: "Panu", dad: "Mikko", mom: "Podo"},
           {name: "Henna", dad: "Matti", mom: "Heidi"},
           {name: "Riikka", dad: "?", mom: "Tuula"},
           {name: "Martta", dad: "Martti", mom: "Tiina"},
           {name: "Kaneli", dad: "Panu", mom: "Martta"},
           {name: "Peikko", dad: "Panu", mom: "Martta"},
           {name: "Utu", dad: "Panu", mom: "Martta"},
           {name: "Kaarna", dad: "Panu", mom: "Riikka"},
           {name: "Liekki", dad: "Panu", mom: "Henna"}];

const crossmap = ls1 => _.chain(e2 => _.map(e => [e, e2], ls1));
const cartesian_square = ls => crossmap(ls)(ls);

const pair_has_common_parent =
	_.apply(_.either(_.eqBy(_.prop('mom')), _.eqBy(_.prop('dad'))));

const sibling_pairs = people =>
	_.map(pair => _.map(_.prop('name'), pair),
	  _.filter(pair_has_common_parent,
	    _.filter(_.apply(_.complement(_.equals)),
	      cartesian_square(people))));

console.log(sibling_pairs(data));

// You can use the currying nature of iterators to write even more
// cryptic code, yay.

const sibling_pairs2 = 
	_.compose(
		_.map(_.map(_.prop('name'))),