Basic

Basic utility for rpscript.
RPScript make heavy use of ramda for utility and data manipulation. A lot of the keywords here are a direct port from ramda.
Besides ramda's methods, there are also utility for event listening, variable assignment, terminal print etc.

Example

rps install basic

Actions

__

See:
Example
log call (replace "{name}" (__) "Hello, {name}!") 'Alice'

abs :: Number → Number

Example
log abs -5.1

add :: Number → Number → Number

See:
Example
log add 3 4

add-index :: ((a ... → b) ... → [a] → ) → (a ..., Int, [a] → b) ... → [a] → )

See:
Example
add-index map | as 'idx'
log call $idx ($val,$idx)=> (identity `${$idx} - ${$val}`) ['f', 'o', 'o', 'b', 'a', 'r']

adjust :: (a → a) → Number → [a] → [a]

See:
Example
adjust (add 10) 1 [1,2,3]

all :: (a → Boolean) → [a] → Boolean

See:
Example
log all (equals 3) [3, 3, 3, 3]

all-pass :: [(...) → Boolean] → (... → Boolean)

See:
Example
log call ( all-pass [ (prop-eq 'name' 'ABC'),(prop-eq 'type' 'org') ] ) {name:'ABC','type':'org'}

always :: a → (* → a)

See:
Example
log call (always 'Tee') 1

and :: a → b → a | b

See:
Example
log and true false

any :: (a → Boolean) → [a] → Boolean

See:
Example
log any (equals 1) [1,2]

any-pass :: [(... → Boolean)] → (... → Boolean)

See:
Example
log call ( any-pass [ (prop-eq 'name' 'ABC'),(prop-eq 'type' 'org') ] ) {name:'K','type':'org'}

ap :: [a → b] → [a] → [b]

See:
Example
log call (ap (concat) (to-upper)) 'Ramda'

aperture :: Number → [a] → [[a]]

See:
Example
log aperture 2 [1,2,3,4,5]

append :: a → [a] → [a]

See:
Example
log append "tests" ["hello"]

apply :: (... → a) → [] → a

See:
Example
log apply math-max [1,2,3,-99,42,6,7]

See:

apply-to :: a → (a → b) → b

See:
Example
log apply-to 42 (add 1)

as :: String → a → a

This is equivalent to variable assignment in programming language.
The assigned variable can be access by prefixing $ on the variable name.

Parameters:
Name Type Description
variable string

Variable name.

value *

Value to be assigned to the variable.

Returns:
* -

Value of the variable.

Example
as 'varName' 1
;print out the value 1
console-log $varName

read 'filename.txt' | as 'varName'
;this will print out the content of 'filename.txt'
console-log $varName

ascend :: Ord b => (a → b) → a → a → Number

See:
Example
log sort (ascend prop "name") [{'name':'z'},{'name':'a'}]

assign :: String → a → a

Parameters:
Name Type Description
variable string

Variable name.

value *

Value to be assigned to the variable.

Returns:
* -

Value of the variable.

assoc :: String → a → {k:v} → {k:v}

See:
Example
log assoc 'd' 4 {a:1,b:2,c:3}

assoc-path :: [Idx] → a → {a} → {a}

See:
Example
log assoc-path ['c','d'] 4 {a:1,b:2,c:{d:0}}

both :: (... → Boolean) → (... → Boolean) → (*... → Boolean)

See:
Example
log call ( both (gt (__) 10) (lt (__) 20) ) 15

call :: (... → a), ... → a

See:
Example
call add 1 2

ceil :: Number → Number

Example
;ceil value
log ceil 5.1

chain :: Chain m => (a → m b) → m a → m b

See:

clamp :: Ord a => a → a → a → a

See:
Example
log clamp 1 10 15

clone :: {} → {}

See:
Example
clone {a:1}

comparator :: ((a,b) → Boolean) → ((a,b) → Number)

See:
Example
comparator ($a,$b) => gt (prop 'age' $a) (prop 'age' $b) | as 'comp'
log sort $comp [{age:50},{age:10},{age:13},{age:25}]

complement :: (... → ) → (*... → Boolean)

See:
Example
log call (complement (is-nil)) 1

compose :: ((y → z), (x → y), ..., (o → p), ((a, b, ..., n) → o)) → ((a, b, ..., n) → z)

See:
Example
log call (compose (to-upper) (concat 'abc ')) 'introduce'

concat :: [a] → [a] → [a]

See:
Example
log concat "hello" "world"

See:

contains :: a → [a] → Boolean

See:
Example
log contains 3 [1,2,3]

converge :: ((x1, x2, ...) → z) → [((a, b, ...) → x1), ((a, b, ...) → x2), ...] → (a → b → ... → z)

See:
Example
assign 'average' converge (divide) [sum, length]
log call $average [1, 2, 3, 4, 5, 6, 7]

count-by :: (a → String) → [a] → {*}

See:
Example
log count-by (floor) [1.0,1.1,1.2,2.3,2.5]

dec :: Number → Number

See:
Example
log dec 42

a → b → a | b

See:
Example
log default-to 10 null

descend :: Ord b => (a → b) → a → a → Number

See:
Example
log sort (descend prop "name") [{'name':'a'},{'name':'z'}]

difference :: [] → [] → [*]

See:
Example
log difference [1,2,3,4] [3,4,5,6]

difference-with ((a,a) → Boolean) → [a] → [a] → [a]

See:
Example
assign 'cmp' eq-props 'a'
log difference-with $cmp [{a: 1}, {a: 2}, {a: 3}] [{a: 3}, {a: 4}]

dissoc :: String → {k:v} → {k:v}

See:
Example
log dissoc 'b' {a:1,b:2,c:3}

dissoc-path :: [Idx] → {k:v} → {k:v}

See:
Example
log dissoc-path ['c','d'] 4 {a:1,b:2,c:{d:5}}

divide :: Number → Number → Number

See:
Example
log divide 6 2

drop :: Number → [a] → [a]

See:
Example
log drop 1 [1,2,3]

drop-last :: Number → [a] → [a]

See:
Example
log drop-last 1 [1,2,3]

drop-last-while :: (a → Boolean) → [a] → [a]

See:

drop-repeats :: [a] → [a]

See:
Example
log drop-repeats [1,1,1,2,3,4,4,4,2,2]

drop-repeats-with :: ((a,a) → Boolean) → [a] → [a]

See:
Example
log drop-repeats-with (eq-by abs) [1,-1,3,-4,-4]

drop-while :: (a → Boolean) → [a] → [a]

See:
Example
log drop-while (eq-by abs) [1,-1,3,-4,-4]

(... → Boolean) → (... → Boolean) → (*... → Boolean)

See:

empty :: a → a

See:
Example
log empty 'abc'

ends-with :: [a] → Boolean

See:
Example
log ends-with 'c' 'abc'

(a → b) → a → a → Boolean

See:
Example
log eq-by (abs) 5 -5

eq-props :: k → {k:v} → {k:v} → Boolean

See:
Example
log eq-props 'a' {a:1} {a:1}

equals :: a → b → Boolean

See:
Example
equals 5 5

evolve :: {k: (v → v)} → {k:v} → {k:v}

See:
Example
log evolve {'firstName': trim } {'firstName': '  Tomato '}

  • → Boolean

See:
Example
log f

filter :: Filterable f => (a → Boolean) → f a → f a

See:
Example
log filter (lt 2) [1,2,3]

find :: (a → Boolean) → [a] → a | undefined

See:
Example
find (prop-eq 'a' 2) [{'a':1},{'a':2},{'a':3}]

find-index :: (a → Boolean) → [a] → Number

See:
Example
find-index (prop-eq 'a' 2) [{'a':1},{'a':2},{'a':3}]

find-last :: (a → Boolean) → [a] → a | undefined

See:
Example
find-last (prop-eq 'a' 2) [{'a':1},{'a':2},{'a':3}]

find-last-index :: (a → Boolean) → [a] → Number

See:
Example
find-last-index (prop-eq 'a' 2) [{'a':1},{'a':2},{'a':3}]

flatten :: [a] → [b]

See:
Example
log flatten [1,2,[3,4]]

floor :: Number → Number

Parameters:
Name Type Description
number number
Returns:
number -

number.

Example
;floor value
floor 5.1

for-each :: (a → *) → [a] → [a]

See:
Example
for-each (log) [1,2,3,4]

for-each-obj-indexed :: ((a,String,StrMap a) → Any) → StrMap a → StrMap a

See:

from-pairs :: [[k,v]] → {k:v}

See:
Example
log from-pairs [['a',1],['b',2],['c',3]]

group-by :: ((a → String) → [a] → {String:[a]}

See:

group-with :: ((a,a) → Boolean) → [a] → [[a]]

See:
Example
log group-with (equals) [0,1,1,2,3,4,6,4]

Ord a => a → a → Boolean

See:
Example
log gt 2 1

Ord a => a → a → Boolean

See:
Example
log gte 2 2

has :: s → {s:x} → Boolean

See:
Example
log has 'name' {name:'Alice'}

head :: [a] → a | undefined

See:
Example
log head ['ff',''aa','lol']

identical :: a → a → Boolean

See:
Example
log identical 1 1

identity :: a → a

See:
Example
log identity 1

if-else :: (… → Boolean) → (… → ) → (… → ) → (… → *)

See:
Example
assign 'ifElse' if-else (has 'count') (over (lens-prop 'count') inc) (assoc 'count' 1)
log call $ifElse {}
log call $ifElse {'count':4}

inc :: Number → Number

See:
Example
log inc 41

index-by :: (a → String) → [{k:v}] → {:{k:v}}

See:
Example
index-by (prop 'id') [{'id':'abc','title':'A'},{'id':'xyz','title':'B'}]

index-of :: a → [a] → Number

See:
Example
index-of 3 [1,2,3,4]

init :: [a] → [a]

Parameters:
Name Type Description
array Array
See:
Example
log init [1, 2, 3]

inner-join :: ((a,b) → Boolean) → [a] → [b] → [a]

See:
Example
assign 'idMatch' ($record, $id) => equals $id prop 'id' $record
log inner-join $idMatch [
   {id: 824, name: 'Richie Furay'},
    {id: 956, name: 'Dewey Martin'},
    {id: 313, name: 'Bruce Palmer'},
    {id: 456, name: 'Stephen Stills'},
    {id: 177, name: 'Neil Young'}] [177, 456, 999]

insert :: Number → a → [a] → [a]

See:
Example
insert 2 'x' [1,2,3,4]

insert-all :: Number → [a] → [a] → [a]

See:
Example
insert-all 2 ['x','y','z'] [1,2,3,4]

intersection :: [ ] → [ ] → [ * ]

See:
Example
log intersection [1,2,3,4] [3,4,5,6]

intersperse :: a → [a] → [a]

See:
Example
intersperse 'n' ['x','y','z']

invert :: {s:x} → {x:[s,...]}

See:
Example
invert {first:'Alice',second:'allen',third:'Alice'}

invert-obj :: {s:x} → {x:s}

See:
Example
invert-obj {first:'Alice',second:'allen'}

is :: ( → {}) → a → Boolean

See:
Example
log to-string is Array [1,2,3]

is-empty :: a → Boolean

See:
Example
log is-empty []

is-nil :: * → Boolean

See:
Example
log is-nil []

join :: String → [a] → String

See:
Example
join ' ' ['x','y','z']

See:
Example
log call (juxt [math-min, math-max]) 3 4 9 -3

@ juxt :: [(a, b, …, m) → n] → ((a, b, …, m) → [n])

See:
Example
keys {a:1,b:2,c:3}

last :: [a] → a | undefined

See:
Example
log last ['x','y','z']

last-index-of :: a → [a] → Number

See:
Example
log last-index-of 'y' ['x','y','y','z']

length :: [a] → Number

See:
Example
length [1,2,3]

listen-on :: String → (...) → EventEmitter → EventEmitter

Parameters:
Name Type Description
event EventEmitter

The object to listen to.

eventName string

Name to listen for event.

Returns:
* -

If condition is met, result of exec. else null.

See:
Example
listen-on 'start' (($output)=>log $output) $emitter

listen-once :: EventEmitter → String → a

Parameters:
Name Type Description
event EventEmitter

The object to listen to.

eventName string

Name to listen for event.

Returns:
* -

If condition is met, result of exec. else null.

See:
Example
listen-once 'connected' $emitter

log :: ...a → a

This is a wrapper for javascript console.log function.

Parameters:
Name Type Description
text List

information to be printed out on the terminal.

Returns:
* -

Similar to text input.

See:
Example
;print 'Hello'
log 'Hello' 'World'
;print 'Hello' again
log $RESULT

lt :: Ord a => a → a → Boolean

See:
Example
log lt 2 1

lte :: Ord a => a → a → Boolean

See:
Example
lte 2 2

map :: Functor f => (a → b) → f a → f b

See:
Example
log map (multiple 2) [1,2,3]

map-accum :: ((acc,x) → (acc,y)) → acc → [x] → (acc, [y])

See:
Example
map-accum (multiple 2) [1,2,3]

map-accum-right :: ((acc,x) → (acc,y)) → acc → [x] → ([y],acc)

See:

map-obj-indexed :: ((,String,Object)→ ) → Object → Object

See:

match :: RegExp → String → [String | Undefined]

See:
Example
log match (regexp "a") "banana"

math-max :: Number → ...Number → Number

Example
max 5.1 1.2 3.3

math-min :: Number → ...Number → Number

Example
;min value
min 5.1 1.2 3.3

math-mod :: Number → Number → Number

See:
Example
log math-mod 17 5

Ord a => a → a → a

Parameters:
Name Type Description
any *
any *
See:
Example
max 2 4

max-by :: Ord a => (a → b) → a → a → a

See:
Example
log max-by (abs) -3 2 -1

See:

See:

merge :: {k:v} → {k:v} → {k:v}

Parameters:
Name Type Description
object Object
object Object
See:
Example
merge {name:'fred',age:10} {age:40}

merge-all :: [{k:v}] → {k:v}

Parameters:
Name Type Description
list Array
See:
Example
merge-all [{'foo':1},{'bar':2},{'baz':3}]

merge-deep-left :: {a} → {a} → {a}

See:

merge :: {a} → {a} → {a}

See:

merge-deep-with :: ((a,a) → a) → {a} → {a} → {a}

See:

merge-deep-with :: ((a,a) → a) → {a} → {a} → {a}

See:

merge-with-key :: ((String, a,a) → a) → {a} → {a} → {a}

See:

min :: Ord a => a → a → a

See:
Example
log min 10 5

min-by :: Ord a => (a → b) → a → a → a

See:
Example
log min-by (abs) -3 2 -1

modulo :: Number → Number → Number

See:
Example
log modulo 17 5

multiply :: Number → Number → Number

See:
Example
log multiply 4 3

negate :: Number → Number

See:
Example
log negate -42

none :: (a → Boolean) → [a] → Boolean

See:

not :: * → Boolean

See:
Example
log not 1

nth :: Number → [a] → a | undefined

See:
Example
nth 1 ['a','b','c']

nth-arg :: Number → ... →

See:
Example
nth-arg 1 'a' 'b' 'c'

obj-of :: String → a → {String:a}

See:
Example
obj-of 'must' ['a','b','c']

of :: a → [a]

See:
Example
log of 42

omit :: [String] → {String:} → {String:}

See:
Example
log omit ['a','b'] {a:1,b:2,c:3,d:4}

or :: a → b → a | b

See:
Example
log or true false

pair :: a → b → (a,b)

See:
Example
log pair 'foo' 'bar'

partition :: Filterable f => (a → Boolean) → f a → [f a, f a]

See:
Example
log partition (contains 's') ['sss','ttt','sas','abc']

path :: [Idx] → {a} → a | undefined

See:
Example
log path ['a','b'] {a:1,{b:2}}

path-eq :: [Idx] → a → {a} → Boolean

See:

path-or :: a → [Idx] → {a} → a

See:
Example
log path-or 'N/A' ['a','b'] {a:1,{b:2}}

path-satisfies ::
(a → Boolean) → [Idx] → {a} → Boolean
Idx = String | Int

See:

pick :: [k] → {k:v} → {k:v}

See:
Example
log pick ['a','b'] {a:1,b:2,c:3,d:4}

pick-all :: [k] → {k:v} → {k:v}

See:
Example
log pick-all ['a','b','g'] {a:1,b:2,c:3,d:4}

pick-by :: ((v,k) → Boolean) → {k:v} → {k:v}

See:
Example
assign 'toUpperCase' ($val,$key) => equals $key to-upper $key
log pick-by $toUpperCase {a: 1, b: 2, A: 3, B: 4}

pipe :: (((a, b, …, n) → o), (o → p), …, (x → y), (y → z)) → ((a, b, …, n) → z)

See:
Example
log call (pipe (negate) (inc)) 3

pluck :: Functor f => k → f {k:v} → f v

See:
Example
pluck (prop 'a') [{a:1},{a:2}]

pow :: Number → Number → Number

Parameters:
Name Type Description
x number
y number
Returns:
number -

number.

Example
;power value
power 5 3

prepend :: a → [a] → [a]

See:
Example
log prepend 'fee' ['fi','fo','fum']

product :: [Number] → Number

See:
Example
log product [2,3]

project :: [k] → [{k:v}] → [{k:v}]

See:
Example
assign 'kids' [{name: 'Abby', age: 7, hair: 'blond', grade: 2},{name: 'Fred', age: 12, hair: 'brown', grade: 7}]
log project ['name', 'grade'] $kids

prop :: s → {s:a} → a | undefined

See:
Example
prop 'x' {x:100}

prop-eq :: String → a → Object → Boolean

See:
Example
log prop-eq 'a' 2 {'a': 2}

prop-is :: Type → String → Object → Boolean

See:
Example
log to-string prop-is Number 'x' {x:1}

prop-or :: a → String → Object → a

See:
Example
log prop-or 'N/A' 'notfound' {x:100}

prop-satisfies :: (a → Boolean) → String → {String: a} → Boolean

See:

props :: [k] → {k:v} → [v]

See:
Example
log props ['x','y'] {x:100,y:50}

random :: Number

Returns:
number -

number.

Example
;random
random

range :: Number → Number → [Number]

See:
Example
log range 1 5

reduce :: ((a,b) → a) → a → [b] → a

See:
Example
log reduce (subtract) 0 [1,2,3,4]

reduce-by :: ((a,b) → a) → a → (b → String) → [b] → {String:a}

See:

reduce-right :: ((a,b) → b) → b → [a] → b

See:
Example
reduce-right (subtract) 0 [1,2,3,4]

reduce-while :: ((a,b) → Boolean) → ((a,b) → a) → a → [b] → a

See:

regexp

Parameters:
Name Type Description
regexp RegExp

regular expression

reject :: Filterable f => (a → Boolean) → f a → f a

See:

remove :: Number → Number → [a] → [a]

See:
Example
log remove 2 3 [1,2,3,4,5,6,7,8]

repeat :: a → n → [a]

See:
Example
log repeat "hi" 5

:: replace :: RegExp|String → String → String → String

See:
Example
log replace "a" "b" "banana"

reverse :: [a] → [a]

See:
Example
log reverse [1,2,3]

round :: Number → Number

Example
log round 1.3

scan :: ((a,b) → a) → a → [b] → [a]

See:
Example
log scan (multiply) 1 [1, 2, 3, 4]

slice :: Number → Number → [a] → [a]

See:
Example
log slice 1 3 ['a','b','c','d']

sort :: ((a,a) → Number) → [a] → [a]

See:
Example
log sort (ascend prop "name") [{'name':'z'},{'name':'a'}]

sort-by :: Ord b => (a → b) → [a] → [a]

See:
Example
log sort-by (prop 0) [[-1,1] , [-2,2] , [-3,3]]

sort-with :: [(a,a) → Number] → [a] → [a]

See:

split :: (String | RegExp) → String → [String]

See:
Example
log split ',' "hello, world, hi"

split-at :: Number → [a] → [[a],[a]]

See:
Example
split-at 1 [1,2,3]

split-every :: Number → [a] → [[a]]

See:
Example
split-every 3 [1,2,3,4,5,6,7]

split-when :: (a → Boolean) → [a] → [[a],[a]]

See:
Example
split-when (equals 3) [1,2,3,4,5,6,7]

starts-with :: [a] → Boolean

See:
Example
starts-with 'a' 'abc'

stdout :: a → a

Parameters:
Name Type Description
text string

information to be printed out on the terminal.

Returns:
* -

Similar to text input.

See:
Example
;print 'Hello'
stdout 'Hello'

stringify :: a → String

Parameters:
Name Type Description
object Object
Returns:
string -

String result

Example
stringify {'a':1,'b':2}

subtract :: Number → Number → Number

See:
Example
log subtract 10 4

sum :: [Number] → Number

See:
Example
log sum [3 5]

symmetric-difference :: [] → [] → [*]

See:
Example
symmetric-difference [1,2,3,4] [3,4,5,6,7]

symmetric-difference-with :: ((a,a) → Boolean) → [a] → [a] → [a]

See:

  • → Boolean

See:
Example
log t

tail :: [a] → [a]

See:
Example
log tail [1,2,3]

take :: [a] → [a]

See:
Example
log take 2 [1,2,3]

take-last :: [a] → [a]

See:
Example
log take-last 2 [1,2,3]

take-last-while :: (a → Boolean) → [a] → [a]

See:

take-while :: (a → Boolean) → [a] → [a]

See:

tap :: (a → *) → a → a

See:

test :: RegExp → String → Boolean

See:
Example
log test (regexp "p") "banana"

times :: (Number → a) → Number → [a]

See:
Example
times (identity) 5

to-lower :: String → String

See:
Example
log to-lower "ABZ"

See:
Example
to-pairs {a:1,b:2,c:3}

to-string :: * → String

See:
Example
log to-string 100

to-upper :: * → String

See:
Example
log to-upper "abc"

transpose :: [[a]] → [[a]]

See:
Example
log transpose [[1,'a'],[2,'b'],[3,'c']]

String → String

See:
Example
log trim " hello   "

truncate :: Number → Number

Example
truncate 1.3

try-catch :: (…x → a) → ((e, …x) → a) → (…x → a)

See:
Example
log call (try-catch (prop 'x') (f)) {x: true}

type :: ( → {}) → String

See:
Example
log type 1

unapply :: ([...] → a) → (... → a)

See:
Example
log unapply (stringify) 1 2 3

unfold :: (a → [b]) → * → [b]

See:

union :: [] → [] → [*]

See:
Example
log union [1,2,3] [2,3,4]

union-with :: ((a,a) → Boolean) → [] → [] → [*]

See:
Example
union-with (eq-by prop 'a') [{a:1}] [{a:1}]

uniq :: [a] → [a]

See:
Example
uniq [1,2,3,3,4,5,4]

uniq-by :: (a → b) → [a] → [a]

See:
Example
uniq-by (abs) [-1, -5, 2, 10, 1, 2]

uniq-with :: ((a,a) → Boolean) → [a] → [a]

See:

unless :: (a → Boolean) → (a → a) → a → a

See:
Example
log call (unless (is-nil) (inc)) 1

unnest :: Chain c => c (c a) → c a

See:
Example
unnest  [1 , [2], [[3]]]

until :: (a → Boolean) → (a → a) → a → a

See:
Example
log call (until (gt (__) 100) (multiply 2) ) 1

update :: Number → a → [a] → [a]

See:
Example
update 1 11 [0,1,2]

use-with :: ((x1, x2, …) → z) → [(a → x1), (b → x2), …] → (a → b → … → z)

See:
Example
assign 'useWith' use-with (pow) [identity, identity]
log call $useWith 3 4

values :: {k: v} → [v]

See:
Example
values {a:1,b:2,c:3}

when :: (a → Boolean) → (a → a) → a → a

See:
Example
assign 'truncate' when (prop-satisfies (gt __ 10) 'length') (pipe (take 10) (append '...') (join '') )
log call $truncate '0123456789ABC'

where :: {String: ( → Boolean} → {String:} → Boolean

See:

where-eq :: {String:} → {String:} → Boolean

See:
Example
where-eq {a:1,b:2} {a:1,b:2}

without :: [a] → [a] → [a]

See:
Example
log without [1,2] [1,2,1,3,4]

xprod :: [a] → [b] → [[a,b]]

See:
Example
log xprod [1,2] ['a','b']

zip :: [a] → [b] → [[a,b]]

See:
Example
log zip [1,2,3] ['a','b','c']

zip-obj :: [String] → [] → {String:}

See:
Example
log zip-obj ['a','b','c'] [1,2,3]

zip-with :: ((a,b) → c) [a] → [b] → [c]

See:
-->