How to use the ramda.map function in ramda

To help you get started, we’ve selected a few ramda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / ramda_v0.x.x / flow_v0.82.x- / test_ramda_v0.x.x_list.js View on Github external
// Ramda works with $ReadOnlyArray as it is immutable.
  const readOnlyArray: $ReadOnlyArray = [1, 2, 3, 4];
  // $ReadOnlyArray with curried permutations:
  const redxsReadOnly3: number = reduce(subtract, 0, readOnlyArray);
  const redxsReadOnly2_1: number = reduce(subtract, 0)(readOnlyArray);
  const redxsReadOnly1_2: number = reduce(subtract)(0, readOnlyArray);
  const redxsReadOnly1_1_1: number = reduce(subtract)(0)(readOnlyArray);

  // $ExpectError reduce will not work with an object.
  reduce(subtract, 0, { foo: 1, bar: 2 });

  // reduceRight
  const redrxs1: number = _.reduceRight(_.add, 10, ns);
  const redrxs2: string = _.reduceRight(_.concat, "", ss);
  const redrxs3: Array = _.reduceRight(_.concat, [])(
    _.map(x => [x], ss)
  );
  const redrxs3a: string = _.reduceRight(
    //$ExpectError
    (acc: string, value: number): string => acc,
    "",
    ns
  );
  const redrxs3b: string = _.reduceRight(
    (value: number, acc: string): string => acc,
    "",
    ns
  );

  // $ExpectError reduceRight does not support reduced.
  const redrxs4: number = _.reduceRight(
    // $ExpectError reduceRight does not support reduced.
github flow-typed / flow-typed / definitions / npm / ramda_v0.x.x / flow_v0.34.x-v0.38.x / test_ramda_v0.x.x_list.js View on Github external
const someObj: { a: string, b: number } = { a: 'a', b: 2 }
  const someMap: { [string]: { a: string, b: number } } = { so: someObj }
  const mapObj: { [string]: string } = _.map((x: { a: string, b: number }): string => x.a)(someMap)

  const functor = {
    x: 1,
    map(f) {
      return f(this.x)
    },
  }

  // Doesn't typecheck (yet) but at least doesn't break
  const mapFxs = _.map(_.toString, functor)

  const double = x => x * 2
  const dxs: Array = _.map(double, [ 1, 2, 3 ])
  const dos: $Shape = _.map(double, obj)

  const appender = (a, b) => [ a + b, a + b ]
  const mapacc:[number, Array] = _.mapAccum(appender, 0, ns)
  const mapacc1:[number, Array] = _.mapAccumRight(appender, 0, ns)

  const nxs: boolean = _.none(x => x > 1, ns)

  const nthxs: ?string = _.nth(2, [ 'curry' ])
  const nthxs1: ?string = _.nth(2)([ 'curry' ])
  //$ExpectError
  const nthxs2: string = _.nth(2, [ 1, 2, 3 ])


  const xxs: Array = _.append(1, [ 1, 2, 3 ])
  const xxxs: Array = _.intersperse(1, [ 1, 2, 3 ])
github dogescript / dogescript / src / dogescript.js View on Github external
function printTokens(lines) {
  R.map(line => {

    // FIXME: This will break when we move to lazy style parsing
    let lineNo = lines.indexOf(line) + 1

    console.log(" {
      process.stdout.write(`<${token.name}>`)
    }, line)
    console.log("\n/>\n")

  }, lines)
}
github infinitered / reactotron / src / Commands / LogCommand.js View on Github external
fs.readFile(fileName, "utf-8", (err, data) => {
      // die quietly for we have failed
      if (err) {
        return
      }
      if (data && is(String, data)) {
        try {
          let lines
          let lineCounter = 0
          const lineBreak = /\n/g
          const contents = split(lineBreak, data)

          // create a new structure of lines
          const sourceLines = map(line => {
            lineCounter = lineCounter + 1
            // i am sorry my tab-based brethern.
            const source = replace(/\t/, "  ", line)
            return {
              isSelected: lineCounter === lineNumber,
              lineNumber: lineCounter,
              source,
            }
          }, contents)

          // should just load it all?
          const showWholeFile = contents.length < SOURCE_LINES_UP + SOURCE_LINES_DOWN

          if (showWholeFile) {
            lines = sourceLines
          } else {
github jaysoo / example-functional-react / src / examples / post-2 / index.js View on Github external
emphasize,
        uppercase,
        sayHello
      )({ name })
    })
  ))

  const footerView = yield footer2

  // Combine everything together!
  return Reader.of(headerView.concat(messageView).concat(footerView))
})

// Hmm, let's style the element as well!
const styledApp = app.map(
  map(x => (
    <div style="{{">{x}</div>
  ))
)

export default element =&gt; {
  ReactDOM.render(
    styledApp
      .runReader({
        color: 'green',
        locale: 'zh',
        title: 'Awesome App',
        author: 'Bob McBob',
        year: 2017
      })
      .fold({ name: 'Alice' }),
    element
github andrewMacmurray / seeds-prototype / src / js / model / shiftTiles.js View on Github external
import { equals, filter, concat, map, complement } from 'ramda'

const isZero = equals(0)
const isTile = complement(isZero)
const filterZeroes = filter(isZero)
const filterTiles = filter(isTile)

export const shift = (board) => concat(filterZeroes(board), filterTiles(board))

// shift zero tiles to the top of the array
export const shiftBoard = map(shift)
github angeloashmore / gatsby-plugin-local-search / src / gatsby-node.js View on Github external
}

  const fields = R.pipe(
    R.head,
    R.keys,
    R.reject(R.equals(ref)),
  )(documents)

  const index = lunr(function() {
    this.ref(ref)
    fields.forEach(x => this.field(x))
    documents.forEach(x => this.add(x))
  })

  const store = R.pipe(
    R.map(R.pick(storeFields)),
    R.indexBy(R.prop(ref)),
  )(documents)

  R.pipe(
    createNodeFactory(name),
    createNode,
  )({
    id: name,
    index: JSON.stringify(index),
    store: JSON.stringify(store),
  })

  return
}
github CyberReboot / CRviz / src / domain / dataset.js View on Github external
([key, value]) =>
      is(Object, value) ? map(concat([key]), pathsIn(value)) : [[key]],
    toPairs(obj)
github OffCourse / offcourse-next / packages / organisms / src / Form / Shell.js View on Github external
linkData() {
    const { links, values } = this.props;
    return map(({ onClick, title }) => {
      return { onClick: () => onClick(values), title };
    }, links);
  }
github benji6 / imlazy / benchmarks / transducers-and-native.js View on Github external
const ramdaTransducerInfiniteBenchmark = xs => R.into([], R.compose(
  R.map(add10),
  R.map(triple),
  R.filter(divisibleBy5),
  R.filter(isEven),
  R.take(length),
), xs)