nodekell
Functional library for nodejs
- currying
- parallel functions
- lazy evaluation
- typescript (ver 3.4 or higher)
- nodejs, web browser(index.js, nodekell.min.js)
Import Module
// const F = require("nodekell");
Quick Example
const v = await F; // 1+3+5+7+9console;//25
const v = await F; // generator to arrayconsole;//[3]
Functions / Examples
currying
functional
- filter
- filterIndexed
- map
- mapIndexed
- take
- takeWhile
- fmap
- flatMap
- flat
- dflat
- reverse
- forEach
- forEachIndexed
- zip
- zip3
- zipWith
- zipWith3
- drop
- dropLast
- dropWhile
- emptyThen
- distinct
- distinctBy
- distinctUntilChanged
- distinctUntilChangedBy
- splitBy
- innerJoin [deprecated][change]
- leftInnerJoin [deprecated]
- rightInnerJoin [deprecated]
- outerJoin [deprecated]
- leftOuterJoin [deprecated]
- rightOuterJoin [deprecated]
- then
- tap
- concat
- union
- scanl
- scanl1
- buffer
- peek
- keys
- values
- removeFirst
- updateAt
- updateFirst
functional / parallel
functional / string
generator
aggregate
- foldl
- foldl1
- reduce
- juxtA
- foldr
- foldr1
- collect
- collectMap
- collectSet
- collectObject
- collectInt8
- collectInt16
- collectInt32
- collectUint8
- collectUint16
- collectUint32
- collectUint8Clamped
- maxBy
- minBy
- max
- min
- some
- every
- count
- sum
- average
- groupBy
- orderBy
- sortBy
- order
- sort
- frequencies
- frequenciesBy
- associateBy
- block
util / else
- _
- juxtO
- sleep
- head
- tail
- interval
- timeout
- withTimeout
- isNil
- cond
- otherwise
- get
- getOrElse
- prop
- has
- find
- findLast
- memoize
- memoizeBy
- equals
- random
- shuffle
- sample
- match
- fnil
- assign
- assign3
- mergeMap
- mergeMapRight
- mergeObject
- mergeObjectRight
- comparator
- insertAt
- doto
- isPrimitive
run
combination left to right functions
first arguments received second functions argument
from second received combine functions
returns promise
const v = await F // 1+3+5+7+9console; // 25 + 1
this expands to
const v = await F; //[0~9]
pipe
combination left to right functions
only first function can use multiple arguments.
return value is promise.
see also compose
const rs = F; //generator to arrayconst a = 15432;const result = await ;//callconsole; //[5,4,3,2,1]
const double1 = F;const a = 1234;const r1 = await ;console; // [2,4,6,8]
const double2 = F; // Array.map const a = 1234;const r2 = await ; // return promiseconsole; // [2,4,6,8]
compose
combination right to left functions
only last function can use multiple arguments.
return value is promise.
see also pipe
const rs = F;const a = 15432;const result = await ;//callconsole; //[5,4,3,2,1]
const double1 = F;const a = 1234;const r1 = await ;console; // [2,4,6,8]
const double2 = F; // Array.map const a = 1234;const r2 = await ; // return promiseconsole; // [2,4,6,8]
curry
if all arguments are not given for the function, it returns the function that stored the argument
const myAdd = F;const myAdd1 = ;const myAdd2 = ;const myAdd3 = ;//<- real callconsole; // print 6
const myAdd = F;const r = ; // <- real callconsole; // print 6
filter
const a = 12345;const filtered = Ffor { console;}//print//2//4
const r = await F; for { console;}//print //2//4
filterIndexed
filter with loop counter
const a = "Apple" "Banana" "Orange" "Strawberry";const filtered = F;//i => 0,1,2,3 //b[a]nana//or[a]nge//str[a]wberry for { console;}//print//"Banana"//"Orange"//"Strawberry"
filterNot
filter return false
const a = 12345;const filtered = Ffor { console;}//print//1//3//5
const r = await F; for { console;}//print //1//3//5
map
const a = 12345;for await const e of F console;//print 2 4 6 8 10
const v = await F;console;//print 2 3 4 5 6
mapIndexed
map with loop counter
const a = 'a''b''c''d''e';const mapped = F; for { console;}//print //a0//b1//c2//d3//34
take
const a = 12345;const t = F;console; // print 1 2 3
const v = await F;console; // print 0 1
takeWhile
const a = 123123;const t = F;console; // print 1, 2
fmap
const a = 12345;const f = F;console; // print [1,2,3,4,5]
const a = Promise Promise 3 4 5;const f = F;console; // print [1,2,3,4,5]
flatMap
same as fmap
flat
const a = Promise Promise 3 4 5;const f = F;console; // print [1,2,3,4,5]
dflat
Similar to flat, but works recursively
const r = F;const c = await F;console;//print [1,2,3,4]
const r = F;const c = await F;console;//print ["H","E","L","L","O"]
reverse
const a = 12345;const t = F;console; // print 5,4,3,2,1
forEach
works concurrency
const beginTime = Date;await F;const endTime = Date;console; // print 121
forEachIndexed
forEach with loop counter
works concurrency
const beginTime = Date;const arr = 'a''b''c''d''e';await F;const endTime = Date;console; // print // 0 'a'// 1 'b'// 2 'c'// 3 'd'// 4 'e'
zip
const a = 12345;const b = 678910;const z = F;const arr = await F;for const e of arr console;//print//[1,6]//[2,7]//[4,9]//[5,0]
zip3
const a = 123;const b = 456;const c = 789;const z = F;const arr = await F;for const e of arr console;//print//[1,4,7]//[2,5,8]//[3,6,9]
const a = 12;const b = 456;const c = 789;const z = F;const arr = await F;for const e of arr console;//print//[1,4,7]//[2,5,8]
zipWith
const a = id:1 id:2;const b = name:"a" name:"b"; const myZip = { return fid sname;}; const z = F;const arr = await F;for const e of arr console;//print//[1,"a"]//[2,"b"]
zipWith3
const a = 123;const b = 456;const c = 789;const z = F;const arr = await F;console;//print [12,15,18]
drop
drop first element
const a = 12345;const r = Fconst result = await F;console; // print [4, 5]
const a = 12345;const r = Fconst result = await F;console; // print []
dropLast
drop last element
const a = 12345;const r = Fconst result = await F;console; // print [1, 2]
const a = 12345;const r = Fconst result = await F;console; // print []
dropWhile
const a = 12341;const r = Fconst result = await F;console; // print [3,4,1]
const a = Promise2341;const r = Fconst result = await F;console; // print [3,4,1]
emptyThen
const v = await F;console; // 2,3,4,5,6
const v = await F console;// 2,3,4
const v = await F
distinct
const a = 121223;const r = F;const result = await F;console; // print 1,2,3
distinctBy
const a = num:1 num:1 num:2;const r = F;const result = await F;for const m of result console;//print//{num:1}//{num:2}
distinctUntilChanged
const a = num:1 num:1 num:2;const r = F;for { console;}//print//{ num: 1 }//{ num: 2 }
const a = 122333445555;const r = F;for { console;}//print//1//2//3//4//5
distinctUntilChangedBy
const a = num:1 num:1 num:2;const r = F;for { console;}//print//{ num: 1 }//{ num: 2 }
const a = 122333445555;const r = F;for { console;}//print//1//2//3//4//5
splitBy
to iterable from any
const helloWorld = "hello world";const r = await F;for { console;}//print //hello//world
innerJoin
deprecated
This function will be replaced by another feature
same as leftInnerJoin
leftInnerJoin
deprecated
support Map, Object({})
const a = id:1 name:"foo" id: 2 name:"bar" id: 3 name:"hoo";const b = id:1 value:3 id: 2 value: 4;const j = await F;const r = await F;console;// print// [{id:1, name:"foo", value:3},// {id:2, name:"bar", value:4}]
rightInnerJoin
deprecated
support Map, object({})
the result is the same as innerJoin, but the output order is right iterator
const a = id:1 value:3; const b = id:1 name:"foo" id: 2 name:"bar" id: 3 name:"hoo";const j = await F;const r = await F;console;// print// [{id:1, name:"foo", value:3}]
outerJoin
deprecated
same as leftOuterJoin
leftOuterJoin
deprecated
support Map, object({})
const a = id:1 name:"foo" id: 2 name:"bar" id: 3 name:"hoo";const b = id:1 value:3 id: 2 value: 4;const j = await F;const r = await Fconsole;// print// [{id:1, name:"foo", value:3},// {id:2, name:"bar", value:4},// {id:3, name:"hoo"}]
rightOuterJoin
deprecated
support Map, object({})
const a = id:1 value:3; const b = id:1 name:"foo" id: 1 name:"bar" id: 1 name:"hoo";const j = await F;const r = await F;console;// print// [{id:1, name:"foo", value:3},// {id:1, name:"bar", value:3},// {id:1, name:"hoo", value:3}]
then
like promise then
see also tap
const v = await F;console;//print//1//2//3//4//5//[2,3,4,5,6]
const v = await F;console;// print// [1,2,3,4,5]
tap
call first argument with second argument
then returns the second argument
return promise wrap
see also then
see also peek
const v = await F;
concat
combines two iterables
const c = F;for { console;}//print [1,2,3,4,5,6]
const v = await F;console;//print [1,2,3,4,5,6]
union
same as concat
scanl
const s = F;const r = await F;console;//print [0,1,3,6]
const r = F;const r = await F;console;//print [64,16,8,8]
scanl1
const s = F;const r = await F;console;//print [1,3,6]
const r = F;const r = await F;console;//print [64,16,8,8]
buffer
creates a list by dividing the iterator at specified interval
const b = F;const c = await F;console; //print [[1],[2],[3],[4],[5]]
const b = F;const c = await F;console; //print [[1,2],[3,4],[5]]
peek
function that perform a function on each element like a map but returns the original instead of the result
this function is useful for debugging.
see also tap
const v = await F;//print //2//3//4//5//6
const a = 12345;const p = Fconst result = await F;console; //not change //print [1,2,3,4,5]
keys
Gets only the Key value from the Collection object.
When an Iterable object traverses into an Array, returns an asynciterator thataverses only the first element.
const m = "a" 1 "b" 2;for awaitconst k of F console;// print "a", "b"const a = { 1 2; 3 4; 5 6;};for await const e of F console;// print [1, 3, 5]s
values
Gets only the Value from the Collection object. When an Iterable object traverses into an Array, returns an asynciterator that averses only the second element.
const m = "a" 1 "b" 2;for awaitconst k of F console;// print// 1// 2const a = { 1 2; 3 4; 5 6;};for await const e of F console;// print// 2// 4
removeFirst
Iterates through A and removes the first element that satisfies the condition.
const arr = 1 2 3 4;for await const e of F console;// print// 2// 3// 4
const arr = 1 2 3 4;const r = F;for { console;}// print// 1// 3// 4
updateAt
Update itererator to the index position
const arr = 12345;const u = F;for { console;}//print//99//2//3//4//5
updateFirst
In itererator, update the first value that matches 2nd argument to 3rd argument.
const arr = 1 2 3;const r = F;for { console;}// print// 99// 2// 3
parallel_set_fetch_count
Set the fetch count of the parallel functions.
after setting, the parallel function is called by count at the same time.
default fetch count is 100
F; await F;//print//0//1//2
F; await F;//print//0//1//2//3//4//5//...//...//198//199//200
pfilter
Same as filter, but calls a fetch count of functions concurrently.
useful for async function or return promise.
//F.parallel_set_fetch_count(100); default is 100const v = await F;console;//print//1//2//3//...//...//99//[0,2]
pmap
Same as map, but calls a fetch count of functions concurrently.
useful for async function or return promise.
//F.parallel_set_fetch_count(100); default is 100const v = await F;console;//print//0//1//2//...//...//99//100//101//[1,2]
pfmap
Same as fmap, but calls a fetch count of functions concurrently.
useful for async function or return promise.
// F.parallel_set_fetch_count(100); default is 100const v = await F; //iterator to arrayconsole;//print//[0]//[1]//[2]//...//...//[99]//[0,42,1,42,2]
pcalls
- async function generator
const gfn2 = { Promise; 2; async await Promise; async await 4;};const c = F;const r = await F;console;//print [1,2,3,4]
- call vaarg async functions
/*like*/Promiseall
const fn1 = { return 1;};const fn2 = { return Promise;};const fn3 = async { return 3;};const fn4 = async { return Promise;};const c = F;const r = await F;console; //print [1,2,3,4]
reFind
Use regular expression return first matching in str
const r = F;console; // print H1
reFindSubmatch
Use regular expression return first matching in str and groups
const r = F;console; // print H1console; // print 1
reFindAll
Use regular expression return all matching in str
const r = F;console;//print ['H1', 'H2']
reFindAllSubmatch
Use regular expression return all matching in str and groups
const r = F;console; // print H1console; // print 1 console; // print H2console; // print 2
range
for const e of F console;//print 0 ~ 9 for const e of F console;//print 10 ~ 1
seq
make iterable(array, set, map, iteratorObject) to asyncIterator
const a = 12345;for awaitconst e of F console;//print 1,2,3,4,5
const a = 1234;for awaitconst e of F console; //print //[1,2] //[3,4]
repeat
const r = F;for { console;}//print //3//3//3//....
const v = await F; //generator => arrayconsole;//print [2,2,2,2,2]
const r = F;for { console;}//print //3//3//3//....
const r = F;for { console;}//print //5//5//5
rangeInterval
first argument is set to the repeat interval
for await const e of F console;//print// [sleep 100]// 0// [sleep 100]// 1// [sleep 100]// 2// [sleep 100]// 3// [sleep 100]// 4// [sleep 100]
for await const e of F console;//print// [sleep 100]// 5// [sleep 100]// 4// [sleep 100]// 3// [sleep 100]// 2// [sleep 100]// 1// [sleep 100]
iterate
apply a function to an argument to produce a sequence
const r = await F;console;//print //[1,2,3,4,5]
const fibo = a1 a0 + a1;const r = await F;//generator to arrayconsole;//print//[0,1,1,2,3,5,8,13,21,34]
enumerate
like python enumerate
const arr = "a" "b" "c" "d" "e";for await const i e of F console;//print// 0 'a'// 1 'b'// 2 'c'// 3 'd'// 4 'e'
foldl
const a = 12345;const sum = await F; console; // print 15
const a = "w""o""r""l""d";const sum = await F; console; // print "helloworld"
foldl1
take 1 items and call foldl
const a = 12345;const sum = await F; console; // print 15;
reduce
same as foldl1
const a = 12345;const sum = await F; console; // print 15;
juxtA
const a = await F;console;//print [5,1]
const a = await F;console;//print [undefined, undefined]
foldr
const arr = 12345;const r = await F;console; // print 15
const arr = 6421;const r = await F;console; // print 32
const arr = "1""2""3""4";const r = await F;console; // print 12345
foldr1
const arr = 12345;const r = await F;console; // print 15
const arr = 6421;const r = await F;console; // print 32
const arr = "1""2""3""4""5";const r = await F;console; // print 12345
collect
iterator or asyncIterator to Array
const mapped = F; console; // print asyncGeneratorconst collected = await F;console; //print [2,3,4,5,6]
const v = await F; // generator => arrayconsole; //[1,4,7,10,13]
collectMap
const a = 1234;const m = await F; // new Map([[1,2],[3,4]])forconst kv of m console;//print //1 2//3 4
collectSet
const a = 123123;const m = await F; //new Set([1,2,3])forconst e of m console;//print //1//2//3
const a = "hello world";const m = await F; //new Set("helo wrd")forconst e of m console;//print //helo wrd
collectObject
const a = 1234;const m = await F; // {1:2,3:4}console;//print { '1': 2, '3': 4 }
collectInt8
collect native array(char)
support async generator(collect + Int8Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Int8Array [ 1, 2, 3, 4 ]
collectInt16
collect native array(short)
support async generator(collect + Int16Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Int16Array [ 1, 2, 3, 4 ]
collectInt32
collect native array(int32)
support async generator(collect + Int32Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Int32Array [ 1, 2, 3, 4 ]
collectUint8
collect native array(unsigned char)
support async generator(collect + Uint8Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Uint8Array [ 1, 2, 3, 4 ]
collectUint16
collect native array(unsigned short)
support async generator(collect + Uint16Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Uint16Array [ 1, 2, 3, 4 ]
collectUint32
collect native array(unsigned int32)
support async generator(collect + Uint32Array.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Uint32Array [ 1, 2, 3, 4 ]
collectUint8Clamped
collect native array(unsigned char)
support async generator(collect + Uint8ClampedArray.from)
if the element is not a number, 0 is assigned
see also collect
const arr = 1234;const c = await F;console; //print Uint32Array [ 1, 2, 3, 4 ]
maxBy
const a = 10987;const r = await F;console; // print 10;
const a = 11098711;const r = await F //compare [0,1,0,0,0,1]console; // print 10
minBy
const a = 010987;const r = await F;console; // print 0
const a = 71098111;const r = await F //compare [0,1,0,0,0,1]console; // 7
max
const a = Promise987;const r = await F;console;//print 10
min
const a = 1098Promise;const r = await F;console;//print 7
some
const a = 12345;const r = await F; //found '2' returnconsole; // true
const r = await F;console; // true
every
const a = 12345;const r = await F; // all elem >= 0 return trueconsole; // true
const a = 12345;const r = await F; //1 ok, 2 ok, 3 no return falseconsole; // false
count
const a = 12345;const n = await F;console; // print 5
sum
const a = 12345;const n = await F;console; // print 15
const a = "abcde";const n = await F;console; // print abcde
average
const a = 12345;const s = await F;console; // print 3
const a = 1020304055;const s = await Fconsole; //print 3.1
groupBy
returns a Map that is aggregated through a function.
key is the return value of the function, and value is the source.
const a = type: "tea" price: 1 type: "tea" price: 2 type: "phone" price: 3 type: "phone" price: 4;//returns new Map(... )const r = await F;console;//print [ { type: 'tea', price: 1 }, { type: 'tea', price: 2 } ]console;//print [ { type: 'phone', price: 3 }, { type: 'phone', price: 4 } ]
orderBy
const a = year: 1990 year: 2005 year: 1958 ; const ASC = 'ASC'; // or 'asc'const DESC = 'desc'; // or 'DESC' const sortedByASC0 = F;const sortedByASC1 = F;const sortedByDESC0 = F;const sortedByDESC1 = F; await F;// [{ year: 1958 }, { year: 1990 }, { year: 2005 }]await F;// [{ year: 2005 }, { year: 1990 }, { year: 1958 }]
const a = 3 6 2 3 7 10 23 21 22 16 13 14 17 20; const sortedByASC = F;const sortedByDESC = F; await F;// [2, 3, 3, 6, 7, 10, 13, 14, 16, 17, 20, 21, 22, 23]await F;// [23, 22, 21, 20, 17, 16, 14, 13, 10, 7, 6, 3, 3, 2]
const a = 'Haskell Brooks Curry'; const sortedByASC = F;const sortedByDESC = F; await F;// [' BCHaekklloorrrssuy']await F;// ['yussrrroollkkeaHCB ']
order
const a = 3 6 2 3 7 10 23 21 22 16 13 14 17 20; const sortedByASC = F;const sortedByDESC = F; await F;// [2, 3, 3, 6, 7, 10, 13, 14, 16, 17, 20, 21, 22, 23]await F;// [23, 22, 21, 20, 17, 16, 14, 13, 10, 7, 6, 3, 3, 2]
const a = 'Haskell Brooks Curry'; const sortedByASC = F;const sortedByDESC = F; await F;// [' BCHaekklloorrrssuy']await F;// ['yussrrroollkkeaHCB ']
sortBy
sorts an array
Returns a new sorted array.
const arr = 4 3 2 5 1;const res = await F;console; // print [1,2,3,4,5]
sort
sorts an array
Returns a new sorted array.
const arr = 4 3 2 5 1;const res = await F;console; // print [1,2,3,4,5]
frequencies
returns a Map. keys are the items that remove duplicates value is the number of times key appears
const arr = 1123455;const r = await F;console;//print//Map { 1 => 2, 2 => 1, 3 => 1, 4 => 1, 5 => 2 }
frequenciesBy
returns a Map. keys are the items that remove duplicates value is the number of times key appears
const arr = 1123455;const r = await F;console;//print//Map { // 1 => 2, // 2 => 1, // 3 => 1, // 4 => 1, // 5 => 2 }
const obj = a:1a:2a:1a:3;const r = await F;console;//print//Map { // 1 => 2, // 2 => 1, // 3 => 1 }
associateBy
returns a Map using iterator. when the function returns Array
it uses the first argument as key and the second argument as value.
when not in an array, the key and value are both return values.
const arr0 = 1 2 3;const m0 = await F;console;//print Map { 1 => 2, 2 => 4, 3 => 6 }
const arr1 = 1 2 3;const m1 = await F;console;//print Map { 2 => 2, 3 => 3, 4 => 4
block
- await promise
- Fetch all the elements of type iterator. When an element returns a promise, it waits for it to finish.
- Fetch all elements of async iterator type.
const r = await F;
const somethingNetworkJob = Promise;const somthingNetworkIterator = { 1;};await F;
_
always returns true when used in equals
always matches when used in match
const r = F;console; //print true
const value = 1 2;F;//print match F._
juxtO
Similar get
, get the value of an array element from an object or map.
const r0 = await ;console; // print [1, 3] const r1 = await ;console; // print [undefined, undefined] const r2 = await ;console; // print [1,2]
sleep
like other language
const beginDate = Date;await F;const endDate = Date;console; // print 1009
head
get first element
warning: if use head for generator, result is not the same
const a = 12345;console; //print 1console; //print 1
const a = F; // make generatorconsole; //print 9console; //print 8console; //print 7
const a = ;try await F;catche console; //print empty iter
tail
get from the second
warning: if use tail for generator, result is not the same
const a = 12345;const t = F;console; // print 2 3 4 5
const a = F; //make generatorfor await const e of F console;for { //a is empty... console;}//print //9//8//7
interval
works like built-in function setInterval
- timer works same time start of the function
- available async function.
- only one function is executed at a time.
F;///print //WORK!// 1 sec //WORK!// 1 sec//...
timeout
@changed iterator timeout use withTimeout instead.
const foo = async { await F;/*something work*/ return 1;};const v = await F;console;//print 1;
try await F; catche console; //print//timeout error//callstack...
withTimeout
it is effective to use timeout at the bottom of the run
const res = ;try const iter = await F; for { res; } catchex console;console;//print //timeout error//callstack...//[1,2,3,4,5,6]
try const a = 12345; const t = F; const v = await F; console;catchex console;//print //timeout error//callstack....
isNil
return false null, undefined, NaN true otherwise
console; // trueconsole; //trueconsole; //trueconsole; // false console; //falseconsole; // falseconsole; // falseconsole; // falseconsole; // false
cond
Requires an even number of arguments
if the first argument is true, it returns the second argument
const r = await F;console; // "tt"
const r = await F;console; // "tt"
otherwise
if Fotherwise console;if F console;//print //WORK!//WORK!
get
call get function or object property
if there is no value, returns undefined
see also prop see also getOrElse
const obj = name: "hello" value: 42 ;console; //print hello
const m = "name" "hello map";console; //print hello mapconsole; //print 1
getOrElse
if object have a get function,
call it or get the properties of that object.
if there is no value, it returns defaultValue.
support Map, Set, any Object
see also get
const m = "name" "hello map" "value" 84;const r0 = F;console; // print hello map const r1 = F;console; // print world
prop
get object property
if there is no value, returns undefined
see also get
const obj = name: "hello" value: 42 ;console; //print hello
propOrElse
get the properties of that object.
if there is no value, it returns defaultValue.
see also prop
const arr = 1 2 3;const r0 = F; // arr[0]console; // print 1 const r1 = F; // arr[100]console; // print 100
has
if there is a has function, check if the value is true after the call. if the has function is missing or returned false, check that the property is not undefined.
const r = F;console; //print true
const r = F;console; //print true
const r = F;console; //print true
find
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print {a:"a1"}
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print undefined
find
returns first element
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print {a:"a1"}
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print undefined
findLast
returns last element
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print {a:"a3"}
const arr = a:"a1" b:"a2" a:"a3";const r = await F;console; // print undefined
memoize
result of the call is stored in the internal cache, and the next call returns the result of the cache
function returns promise
const memFn = { console;};const m = F;await ; await ; await ; //print//callOnce
const beginTime = Date;const memFibo = F;console;console;// print// 832040// Elapsed time:1msec
memoizeBy
result of the call is stored in the internal cache, and the next call returns the result of the cache
first argument is the key value to be stored in the internal cache
function returns promise
const memFn = { console;};const m = F;await ; await ; await ; //print//callOnce
const beginTime = Date;const memFibo = F;console;console;// print// 832040// Elapsed time:1msec
random
internally use crypto.randomBytes
const r0 = F; // print 0 ~ 4294967295const r1 = F; // print 0 ~ 9const r2 = F; // print 1 ~ 41, maximum range: 4294967295
equals
compares deep strict equals
const a = 1;F; // trueF; // false
const o = a:1;F; // true
F; // trueF; // true
shuffle
return a random permutation of iterator
await is not required to use for an array.
const arr = 12345;const sf = F;console;//print [5,3,2,1,4]
const a = { 1; 2; 3; 4; 5;};const sf = await F; // await requiredconsole;//print [5,3,2,1,4];
const a = { 1; 2; 3; 4; 5;};const sf = await F; // await requiredconsole;//print [5,3,2,1,4];
sample
return a random element of iterator
await is not required to use for an array.
const r = F;console; //print 1 ~ 6 random
const r = await F;console; //print 0 ~ 100 random
match
pattern matching
call or return first match
From the second argument requires a pair of arguments.
pair first argument is the value to compare, second argument is the function to use
F._ matches all patterns.
see also _
const value = 1 2; F; //print match [1, any]
const value = 1 2;const res = F;console;//print match 4
fnil
first argument is the calling function. from the second argument,
the argument is entered as the first argument.
returns a function calls first argument,
if a function has a argument, it acts as a substitute for an existing argument.
{ console;} const sayHelloWithDefault = F;; // print hello javascript; // print hello leanne
assign
curry with Object.assign
Returns the target object.
const obj0 = a: 1 ;const obj1 = b: 1 ;const r = F;console;//print { a: 1, b: 1 };
assign3
curry with Object.assign
Returns the target object.
must have at least 3 arguments
const obj0 = a: 1 ;const obj1 = b: 1 ;const obj2 = c: 1 ;const r = F;console;//print { a: 1, b: 1, c: 1 };
mergeMap
Create a new Map by combining the arguments of the function.
If the key exists, the value on the right is used.
const m1 = 1 2 3 4;const m2 = 5 6 7 8;const r1 = await F;console; // print Map { 1 => 2, 3 => 4, 5 => 6, 7 => 8 } const m3 = 1 2 3 4;const o1 = 5: 6 7: 8 ;const r2 = await F;console; // print Map { 1 => 2, 3 => 4, '5' => 6, '7' => 8 }
mergeMapRight
Create a new Map by combining the arguments of the function.
If the key exists, the value on the left is used.
const m1 = 1 2 3 4;const m2 = 5 6 7 8;const r1 = await F;console; // print Map { 5 => 6, 7 => 8, 1 => 2, 3 => 4 } const m2 = 1 2 3 4;const o2 = 5: 6 7: 8 ;const r2 = await F;console; // Map { '5' => 6, '7' => 8, 1 => 2, 3 => 4 }
mergeObject
Create a new object by combining the arguments of the function.
If the key exists, the value on the right is used.
const m1 = 1 2 3 4;const o1 = 5: 6 7: 8 ;const r1 = await F;console; // print { '1': 2, '3': 4, '5': 6, '7': 8 }
mergeObjectRight
Create a new object by combining the arguments of the function.
If the key exists, the value on the left is used.
const m1 = 1 2 3 4;const o1 = 5: 6 7: 8 ;const r1 = await F;console; // print { '1': 2, '3': 4, '5': 6, '7': 8 }
comparator
Creates a function that can be used as a comparison using '<' on an existing '-'.
const cmp = F;console; // print -1
const arr = 5 4 1 2 3;arr;console; // print [1, 2, 3, 4, 5];
const arr = 5 4 1 2 3;const r0 = await F;console; // print [5, 4, 3, 2, 1]
insertAt
Add iterator to the index position of iterator received as an argument.
If index is greater than the length of iterator, it is added to the end of iterator.
const arr = 12345;const ins = F; // insert 6 in 0 indexconst r = await F; //generator to arrayconsole; // print [6, 1, 2, 3, 4, 5]
const arr = 12345;const ins = F; // insert 6 in last indexconst r = await F; //generator to arrayconsole; // print [1, 2, 3, 4, 5, 6]
doto
It takes a value and a function and calls the function by value. Pass the value to the first argument when calling the function.
const r = await F;console; // print { a: 3 };
const r = await F;console; // print { a: 3, b: 2 };
isPrimitive
check string, number, bigint, boolean, null, undefined, and symbol.
notice
bigint is also a primitive type,
but due to typescript compatibility issues the correct type may not be displayed.
F // trueF // trueF // trueF; // trueF // trueF // falseF // falseF // falseF // falseF // false