R.apex

  • Docs
  • Tutorials
Docs Menu
  • Func
  • R.Funcs
    • Conversion Funcs
    • Arithmetic Funcs
    • Logic Funcs
    • Relation Funcs
    • Function Funcs
    • Comparator Funcs
    • Condition Funcs
    • List Funcs
    • String Funcs
    • Map Funcs
    • Utility Funcs
    • Database Funcs
  • R.Instance
    • Creation Methods
    • Conversion Methods
    • Methods

Methods Guide

methods of R

adjust

Update the element at index with the function.

R.with(1, 2, 3).adjust(R.add.apply(1), 1).debug(); // (1, 3, 3)

all

Check if all elements match the predicate.

R.with(1, 2, 3).all(R.equals.apply(1)).debug(); // false

append

Append the element to the elements.

R.with(1, 2, 3).append(4).debug(); // (1, 2, 3, 4)

assoc

Associate the value to the key.

R.withObj('name', 'value').assoc('name', 'newValue').debug(); // {name=newValue}

capitalize

Return a new string with the first letter in uppercase.

R.of('cat').capitalize().debug(); // Cat

clamp

Return a value that is limited between the min and the max.

R.of(4).clamp(1, 3).debug(); // 3

compact

Remove null values from the elements.

R.with('a', null, 0).compact().debug();
// (a, 0)

concat

Concatenate the other.

R.with(1, 2, 3).concat(R.with(4, 5, 6)).debug();

contains

Check if the target is contained.

R.with(1, 2, 3).contains(2).debug(); // true

containsBy

Check if the target is contained by the predicate.

R.with(1, 2, 3).containsBy(R.equals, 2).debug(); // true

containsKey

Check if the key is contained.

R.withObj('name', 'test').containsKey('name').debug(); // true

countBy

Get a result of count mapped by the key.

R.with(1, 2, 2).countBy(R.identity).debug();

debug

Print debug information.

R.with(1, 2).debug(); // (1, 2)

defaultTo

Get the default value.

R.of(null).defaultTo(3).debug(); // 3

difference

Do a difference with the other object.

R.with(1, 2, 3).difference(R.with(2, 3, 4)).debug(); // (1)

dissoc

Remove the value mapped by the key.

R.withObj('name', 'value').dissoc('name').debug(); // {}

doClone

Get a clone.

R.with(1, 2, 3).doClone().debug(); // (1, 2, 3)

doInsert

Insert the element at the index.

R.with(1, 2, 3).doInsert(1, 'x').debug(); // (1, x, 2, 3)

doInsertAll

Insert all the elements at the index.

R.with(1, 2, 3).doInsertAll(1, R.with('x', 'y')).debug(); // (1, x, y, 2, 3)

doJoin

Join the elements with the separator.

R.with(1, 2, 3).doJoin('-').debug(); // 1-2-3

doMap

Map a function over the elements.

R.with(1, 2, 3).doMap(R.add.apply(1)).debug(); // (2, 3, 4)

doMerge

Merge the source.

R.withObj('name', 'test').doMerge(R.withObj('name', 'newTest')).debug();
// {name=newTest}

doUpdate

Update the element at the specified index.

R.with(1, 2, 3).doUpdate(1, 3).debug(); // (1, 3, 3)

drop

Drop the first N elements.

R.with(1, 2, 3).drop(2).debug(); // (3)

dropRight

Drop the first N elements from right.

R.with(1, 2, 3).dropRight(2).debug(); // (1)

dropRightWhile

Drop from right until the predicate is not satisfied.

R.with(1, 2, 3).dropRightWhile(R.equals.apply(1)).debug(); // (1, 2, 3)

dropWhile

Drop until the predicate is not satisfied.

R.with(1, 2, 3).dropWhile(R.equals.apply(1)).debug(); // (2, 3)

endsWith

Check if the elements end with the value.

R.of('abc').endsWith('bc').debug(); // true

every

Check if every element matches the predicate.

R.with(1, 2, 3).every(R.equals.apply(1)).debug(); // false

evolve

Apply the function to the value mapped by the same key and calculate the evolved object.

R.withObj('name', 'test').evolve(new Map{ 'name' => R.append.apply('more') }).debug();
// {name=testmore}

filter

Call the function to filter the elements of instance R.

R.with(1, 2, 3).filter(R.equals.apply(2)).debug(); // (2)
R.with(new Account(Description = 'desc'), new Account()).filter('Description').debug(); // (Account:{Description=desc})
R.with(new Account(Description = 'desc'), new Account()).filter('Description', 'desc').debug(); // (Account:{Description=desc})
R.with(new Account(Description = 'desc'), new Account()).filter(new Map{ 'Description' => 'desc' }).debug();
// (Account:{Description=desc})

find

Find the first element that satisfies the predicate.

R.with(1, 2, 3).find(R.equals.apply(2)).debug(); // 2

findIndex

Find the index of the first element that matches the predicate.

R.with(1, 2, 3).findIndex(R.equals.apply(2)).debug(); // 1

findLast

Find the first element that satisfies the predicate from last.

R.with(1, 2, 3).findLast(R.equals.apply(2)).debug(); // 2

findLastIndex

Find the index of the first element that matches the predicate from last.

R.with(1, 2, 3).findLastIndex(R.equals.apply(2)).debug(); // 1

first

Get the first element.

R.with(1, 2, 3).first().debug(); // 1

flatten

Flatten the elements recursively.

R.with(1, new List{ 2, new List{ 3 } }, 4).flatten().debug();
// (1, 2, 3, 4)

forEach

Call the function to each element of instance R.

R.with(1, 2, 3).forEach(R.debug);
// 1
// 2
// 3

fromPairs

Convert from a list of pairs to a map.

R.with(new R.Pair('name', 'test')).fromPairs().debug();
// {name=test}

groupBy

Get a result of count mapped by the key.

R.with(1, 2, 2).countBy(R.identity).debug();

head

Get the first element.

R.with(1, 2, 3).head().debug(); // 1

indexBy

Get object indexed by the key.

R.with(1, 2, 2).indexBy(R.identity).debug();

indexOf

Get the index of the target.

R.with(1, 2, 3).indexOf(2).debug(); // 1

init

Get the elements except the last.

R.with(1, 2, 3).init().debug(); // (1, 2)

intersection

Do an intersection with the other object.

R.with(1, 2, 3).intersection(R.with(2, 3, 4)).debug(); // (2, 3)

invert

Get an inverted map, values mapped by duplicate keys are put in a list.

R.withObj('name', 'test').invert().debug();

invertObj

Get an inverted map.

R.withObj('name', 'test').invertObj().debug();
// {test=name}

isEmpty

Check if it is empty.

R.with(1, 2, 3).isEmpty().debug(); // false

keys

Get the keys of the wrapped map.

R.withObj('name', 'test').keys().debug();
// {name}

last

Get the last element.

R.with(1, 2, 3).last().debug(); // 3

lastIndexOf

Get the index of the target from the last.

R.with(1, 2, 3).lastIndexOf(2).debug(); // 1

length

Get the length, same as size().

R.with(1, 2, 3).length().debug(); // 3

match

Get a list of matched groups after doing a regex match.

R.of('abc').match('.*(a).*').debug();
// (abc, a)

none

Check if none of the elements matches the predicate.

R.with(1, 2, 3).none(R.equals.apply(1)).debug(); // false

nth

Get the nth element.

R.with(1, 2, 3).nth(1).debug(); // 2

omit

Omit the values specified by the list of keys.

R.of(new Account(FirstName='test', Description='desc')).omit(new List{ 'Description' }).debug();
// {FirstName=test}

pad

Pad the string to the length.

R.of('cat').pad(5, '*').debug(); // *cat*

padLeft

Pad the string to the length from the left.

R.of('cat').padLeft(5, '*').debug(); // **cat

padRight

Pad the string to the length from the right.

R.of('cat').padRight(5, '*').debug(); // cat**

partition

Create a paritioned pair using the predicate.

R.with(1, 2, 3).partition(R.equals.apply(1)).debug();
// Pair:[fst=(1), snd=(2, 3)]

pick

Pick the values specified by the list of keys.

R.of(new Account(FirstName='test', Description='desc')).pick(new List{ 'Description' }).debug();
// {Description=desc}

pluck

Extract the field out of the object to a new list.

R.with(new Account(Description='desc')).pluck('Description').debug();
// (desc)

prepend

Prepend the element to the elements.

R.with(1, 2, 3).prepend(4).debug(); // (4, 1, 2, 3)

project

Project a list of objects using the list of fields.

R.with(new Account(Description='desc', FirstName='test')).project(new List{ 'Description' }).debug();
// ({Description=desc})

reduce

Reduce over the elements.

R.with(1, 2, 3).reduce(R.add, 0).debug(); // 6

reject

Reject the elements by checking with the predicate.

R.with(new Account(Description = 'desc'), new Account()).reject((Func)R.complement.run(R.has.apply('Description'))).debug();
// (Account:{Description=desc})

R.with(new Account(Description = 'desc'), new Account()).reject('Description').debug();
// (Account:{})

R.with(new Account(Description = 'desc'), new Account()).reject('Description', 'desc').debug();
// (Account:{})

R.with(new Account(Description = 'desc'), new Account()).reject(new Map{ 'Description' => 'desc' }).debug();
// (Account:{})

remove

Remove elements starting at the index and specified by the count.

R.with(1, 2, 3).remove(1, 3).debug();
// (1)

repeat

Create a list of elements by repeating the element.

R.of('a').repeat(3).debug(); // (a, a, a)

replace

Replace the string according to the pattern and replacement.

R.of('I love cats').replace('cat', 'dog').debug();
// I love dogs

replaceAll

Replace all the strings according to the pattern and replacement.

R.of('I love cats').replaceAll('cat', 'dog').debug();
// I love dogs

reverse

Reverse the elements.

R.with(1, 2, 3).reverse().debug(); // (3, 2, 1)

sample

Get a random element.

R.with(1, 2, 3).sample().debug(); // 3

sampleSize

Get a list of random elements.

R.with(1, 2, 3).sampleSize(2).debug(); // (3, 1)

shuffle

Create a shuffled list of elements.

R.with(1, 2, 3).shuffle().debug(); // (3, 1, 2)

size

Get the size, same as length().

R.with(1, 2, 3).size().debug(); // 3

slice

Get a slice of the elements.

R.with(1, 2, 3).slice(1, 2).debug(); // (2)

some

Check if some elements match the predicate.

R.with(1, 2, 3).some(R.equals.apply(1)).debug(); // true

sortBy

Sort the elements by the comparator.

R.with(new Account(Description='abc'), new Account(Description='def')).sortBy((Func)R.descend.run(R.prop.apply('Description'))).debug();
// (Account:{Description=def}, Account:{Description=abc})

sortDefault

Sort the elements by default.

R.with(3, 2, 1).sortDefault().debug(); // (1, 2, 3)

split

Split the string by the separator.

R.of('a/b/c').split('/').debug();
// (a, b, c)

startsWith

Check if the elements start with the value.

R.with(1, 2, 3).startsWith(new List{ 1, 2 }).debug(); // true

sum

Get the sum.

R.with(1, 2, 3).sum().debug(); // 6

tail

Get the elements except the first.

R.with(1, 2, 3).tail().debug(); // (2, 3)

take

Take the first N elements.

R.with(1, 2, 3).take(2).debug(); // (1, 2)

takeRight

Take the first N elements from right.

R.with(1, 2, 3).takeRight(2).debug(); // (2, 3)

takeRightWhile

Take elements from right until the predicate is not satisfied.

R.with(1, 2, 3).takeRightWhile(R.equals.apply(1)).debug(); // ()

takeWhile

Take elements until the predicate is not satisfied.

R.with(1, 2, 3).takeWhile(R.equals.apply(1)).debug(); // (1)

test

Test the string according to the pattern.

R.of('cat').test('.*b.*').debug(); // false

toLower

Convert the string to lowercase.

R.of('Cat').toLower().debug(); // cat

toPairs

Convert a map to a list of pairs.

R.withObj('name', 'test').toPairs().debug();
// (Pair:[fst=name, snd=test])

toUpper

Convert the string to uppercase.

R.of('cat').toUpper().debug(); // CAT

transform

Transform the wrapped value using the function.

R.with(1, 2, 3).transform(R.size).debug(); // 3

trim

Trim the string.

R.of('  a  ').trim().debug(); // a

union

Do a union with the other object.

R.with(1, 2, 3).union(R.with(2, 3, 4)).debug(); // (1, 2, 3, 4)

uniq

Return unique elements.

R.with(1, 2, 2).uniq().debug(); // (1, 2)

unnest

Flatten the elements by one level.

R.with(1, new List{ 2, 3 }, 4).unnest().debug();
// (1, 2, 3, 4)

values

Get the values of the wrapped map.

R.withObj('name', 'test').values().debug();
// (test)

without

Same as difference.

R.with(1, 2, 3).without(R.with(2, 3, 4)).debug(); // (1)

xor

Do an xor with the other object.

R.with(1, 2, 3).xor(R.with(2, 3, 4)).debug(); // (1, 4)

zip

Create a zipped list of pairs according to the mList.

R.with('a', 'b').zip(new List{ 1, 2 }).debug();
// (Pair:[fst=1, snd=a], Pair:[fst=2, snd=b])

zipObj

Create a zipped map according to the mList.

R.with('a', 'b').zipObj(new List{ 1, 2 }).debug();
// {1=a, 2=b}

Contribute on Github! Edit this section.