Function
Static Public Summary | ||
public |
集合の要素を、指定した関数の引数に割り当てて呼び出します。foo(x, y)をargs = [1, 2]で呼び出す場合に、apply(foo, args)としてください。 |
|
public |
butlast(coll: *[] | iterator | null): iterator | null 最後の要素を除いた集合のイテレーターを返します。 |
|
public |
call(x: *, fs: function[] | iterator): * 指定された引数を使用して最初の関数を呼び出し、その結果を引数に次の関数を呼び出します。引数にコードの一部を使用したい場合は、tCallマクロを使用してください。 |
|
public |
関数を合成します。 |
|
public |
complement(f: function): function 引数の関数の戻り値の真偽を逆にした関数を生成します。 |
|
public |
* concat(xss: *[][] | iterator[]): iterator 複数の集合を結合します。 |
|
public |
condCall(x: *, clauses: *[]): * 値と、条件と関数のペアの集合をとり、条件が真の場合は値を引数に関数を実行した戻り値を返します。条件が偽の場合は値をそのまま返します。 さらに条件と関数のペアがある場合は、条件が真の場合は一つ前の結果を引数にして関数を実行します。条件が儀の場合は、一つ前の処理の結果をそのまま返します。 |
|
public |
* conj(coll: *[] | iterator | null, x: *): iterator 集合の最後に要素を追加し、イテレーターを返します。Clojureのconjとは異なり、コレクションではなくイテレーターを返します。 |
|
public |
* cons(x: *, coll: *[] | iterator | null): iterator 集合の先頭に要素を追加し、イテレーターを返します。 |
|
public |
constantly(x: *): function 指定した引数を返す関数を生成します。 |
|
public |
集合に含まれる要素の数を返します。 |
|
public |
* cycle(coll: *[] | iterator | null): iterator 集合を繰り返した集合のイテレーターを返します。 |
|
public |
引数から1を引きます。 |
|
public |
* dedupe(coll: *[] | iterator | null): iterator 一つ前の要素と値が異なる要素のみの集合のイテレーターを返します。 |
|
public |
* distinct(coll: *[] | iterator | null): iterator 集合から重複した要素を削除したイテレーターを返します。 |
|
public |
集合から先頭n個の要素を削除したイテレーターを返します。 |
|
public |
* dropLast(args: *[]): iterator 最後のn個の要素を削除したイテレーターを返します。 |
|
public |
先頭から続く条件を満たす要素を削除したイテレーターを返します。 |
|
public |
集合のすべての要素が条件を満たすか確認します。 |
|
public |
引数で指定されるすべての条件を満たすかを確認する関数を生成します。 |
|
public |
ffirst(coll: *[][] | iterator | null): * 集合の最初の要素の最初の要素を返します。first(first(xoll))と同じです。 |
|
public |
集合から条件を満たす要素を抽出し、その要素の集合のイテレーターを返します。 |
|
public |
first(coll: *[] | iterator): * 集合の最初の要素を返します。 |
|
public |
flatten(coll: *[][] | iterator | null): * 集合の集合を集合に変換し、そのイテレーターを返します。 |
|
public |
fnext(coll: *[] | iterator | null): * 集合の2番目以降の要素の最初の要素(つまり2番目の要素)を返します。first(next(coll))と同じです。 |
|
public |
引数がnullだった場合に、指定されたデフォルト値に置き換えて実行する関数を生成します。 |
|
public |
集合の要素をグループ単位に分けたマップを返します。 |
|
public |
identity(x: *): * 引数の値をそのまま返します。文法上関数を指定しなければならないのだけどやる処理がない場合に使用してください。 |
|
public |
引数に1を足します。 |
|
public |
* interleave(colls: *[][] | iterator[]): * 1つ目の集合の最初の要素、2つ目の集合の最初の要素……、1つ目の要素の2番目の要素、2つ目の要素の2番目の要素……という集合のイテレーターを返します。 |
|
public |
* interpose(sep: *, coll: *[] | iterator | null): iterator 集合の要素の間にセパレーターを挟み込んだ集合のイテレーターを返します。 |
|
public |
集合が空か調べます。 |
|
public |
isSequencial(x: *): boolean イテレーターを取得できるか(イテラブルか)確認します。 |
|
public |
初期値、初期値を引数に関数を呼び出した戻り値、その戻り値を引数に関数を呼び出した戻り値……のイテレーターを返します。 |
|
public |
引数で指定した関数群の戻り値の集合へのイテレーターを返す関数を生成します。 |
|
public |
集合の要素を引数に取る関数を実行した結果がnullでない場合の集合のイテレーターを返します。 |
|
public |
keepIndexed(f: function, coll: *[] | iterator | null): iterator インデックスと集合の要素を引数に取る関数を実行した結果がnullでない場合の集合のイテレーターを返します。 |
|
public |
last(coll: *[] | iterator | null): * 集合の最後の要素を返します。 |
|
public |
イテレーターが必要となったときまで、関数の実行を遅延します。lazySeqマクロを使用すれば、関数呼び出しをそのまま記述できます。 |
|
public |
* map(f: *, colls: ...*) |
|
public |
mapIndexed(f: function, coll: *[] | iterator | null): iterator インデックスと集合の要素を引数に取る関数を実行した結果の集合のイテレーターを返します。map(f, range(), coll)と同じです。 |
|
public |
mapした結果をconcatします。apply(concat, map(f, coll))と同じです。 |
|
public |
max(xs: *[]): * 引数の中で最大の値を返します。 |
|
public |
maxKey(k: funciton, xs: *[]): * k(x)が最大のxを返します。 |
|
public |
maxKey(k: funciton, xs: *[]): * k(x)が最小のxを返します。 |
|
public |
関数をメモ化します。 |
|
public |
min(xs: *[]): * 引数の中で最小の値を返します。 |
|
public |
next(coll: *[] | iterator | null): iterator | null 集合の2番目の要素から最後の要素までのイテレーターを返します。集合の要素数が2未満の場合は、nullを返します。空集合のイテレーターが必要な場合は、restを使用してください。 |
|
public |
nfirst(coll: *[] | iterator | null): iterator | null 集合の最初の要素の2番目の要素から最後の要素までのイテレーターを返します。next(first(coll))と同じです。 |
|
public |
nnext(coll: *[] | iterator | null): iterator | null 集合の2番目以降の要素の2番目以降の要素(つまり3番目以降の要素)を返します。next(next(coll))と同じです。 |
|
public |
集合の要素の中に、条件を満たすものが1つもないことを確認します。someの反対です。 |
|
public |
集合の要素の中に、条件を満たさないものがあるか確認します。everyの反対です。 |
|
public |
集合のn番目の要素を取得します。 |
|
public |
集合のn番目以降のイテレーターを返します。 |
|
public |
集合のn番目以降のイテレーターを返します。 |
|
public |
関数に引数を部分適用します。 |
|
public |
* partition(args: *[]): iterator 集合を分割します。分割した余りは返されません。 |
|
public |
* partitionAll(args: *[]): iterator 集合を分割します。partitionとは異なり、分割した余りも返します。 |
|
public |
* partitionBy(f: function, coll: *[] | iterator | null): iterator 指定した関数の戻り値が変更になるたびに、集合を分割します。 |
|
public |
最初の関数の戻り値を入力にして次の関数を実行、その戻り値を入力にしてその次の関数を実行……のように、関数をパイプで接続して実行する関数を生成します。 |
|
public |
randNth(coll: *[] | iterator | null): * 要素を1つランダムに抽出します。 |
|
public |
randomSample(prob: number, coll: *[] | iterator | null): iterator 各要素を確率probで抽出します。一般に、抽出される要素の数がcount(coll) * probと一致するとは限りません。 n個必要で順序が安定でなくても良い場合は、take(n, shuffle(coll))を使用してください。 |
|
public |
範囲を表現するイテレーターを返します。 |
|
public |
reduce(args: *[]): * 畳み込みます。f(f(f(init, coll[0]), coll[1]), coll[2])...の結果を返します。 |
|
public |
reduceを途中で終了させます。 |
|
public |
* reductions(args: *[]): iterator reduceの途中経過も含めて、イテレーターで返します。 |
|
public |
条件を満たす要素を除いた集合のイテレーターを返します。 |
|
public |
* repeat(args: *[]): iterator 値を繰り返す集合のイテレーターを返します。 |
|
public |
* repeatedly(args: *[]): iterator 関数を繰り返して実行し、その結果を返します。 |
|
public |
集合の要素をマップの値で置き換えます。 |
|
public |
rest(coll: *[] | iterator | null): iterator 集合の2番目の要素から最後の要素までのイテレーターを返します。集合の要素数が2未満の場合は、空集合のイテレーターを返します。 |
|
public |
reverse(coll: *[] | iterator | null): iterator 集合の要素を逆順にします。 |
|
public |
rseq(coll: *[]): iterator | null 配列を逆順に辿るイテレーターを返します。 |
|
public |
second(coll: *[] | iterator | null): * 2番目の要素を抽出します。 |
|
public |
seq(coll: *[] | iterator | null): iterator | null 集合からイテレーターを取得します。集合が空の場合はnullを返します。 |
|
public |
sequence(coll: *[] | iterator | null): iterator 集合からイテレーターを取得します。 |
|
public |
* shuffle(coll: *[] | iterator | null): iterator 集合をシャッフルします。 |
|
public |
集合の中に条件を満たすものがあるか確認します。条件は関数で指定し、最初に真になった関数の戻り値を返します。最後まで真にならなかった場合は、nullを返します。 |
|
public |
someCall(x: *, fs: function[] | iterator): * 指定された引数を使用して最初の関数を呼び出し、その結果を引数に次の関数を呼び出します。関数がnullを返した場合は、そこで処理を完了します。 引数にコードの一部を使用したい場合は、tSomeCallマクロを使用してください。 |
|
public |
引数で指定される条件を一つでも満たすかを確認する関数を生成します。 |
|
public |
sort(args: *[]): iterator ソートします。 |
|
public |
sortBy(args: *[]): iterator 関数の戻り値でソートします。 |
|
public |
指定した箇所で集合を分割します。 |
|
public |
先頭から続く指定した条件を満たす要素の集合tと、そうでない要素の集合に分割します。[takeWhile(pred, coll), dropWhile(pred, coll)]です。 |
|
public |
集合の先頭n個の要素のイテレーターを返します。 |
|
public |
集合の末尾n個の要素のイテレーターを返します。 |
|
public |
n個単位に要素を抽出した集合のイテレーターを返します。 |
|
public |
先頭から続く、条件を満たす要素を抽出したイテレーターを返します。 |
|
public |
イテレーターを複数に分けます。 |
Static Public
public apply(f: function, args: *[] | iterator | null): * source
import apply from 'lajure/src/apply.js'
集合の要素を、指定した関数の引数に割り当てて呼び出します。foo(x, y)をargs = [1, 2]で呼び出す場合に、apply(foo, args)としてください。
Params:
Name | Type | Attribute | Description |
f | function | 関数 |
|
args | *[] | iterator | null | 関数の引数の集合 |
Return:
* | 関数fの戻り値 |
Example:
apply(foo, args);
// = foo(...args);
filter(partial(apply, foo), [[1, 2], [3, 4]]);
// = filter(args => foo(...args), [[1, 2], [3, 4]]);
public butlast(coll: *[] | iterator | null): iterator | null source
import butlast from 'lajure/src/butlast.js'
最後の要素を除いた集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | null | 最後の要素を除いた集合のイテレーター |
public call(x: *, fs: function[] | iterator): * source
import call from 'lajure/src/call.js'
指定された引数を使用して最初の関数を呼び出し、その結果を引数に次の関数を呼び出します。引数にコードの一部を使用したい場合は、tCallマクロを使用してください。
Params:
Name | Type | Attribute | Description |
x | * | 最初の関数の引数 |
|
fs | function[] | iterator | 順番に呼び出す関数の集合 |
Return:
* | 最後の関数の戻り値 |
Example:
call(x, foo, bar);
// = bar(foo(x));
tCall(iterate(inc, 1),
takeWhile(x => x < 10),
filter(x => x % 2));
// = call(iterate(inc, 1), xs => takeWhile(x => x < 10, xs), xs => filter(x => x % 2, xs))
// = filter(x => x % 2, takeWhile(x => x < 10, iterate(inc, 1)))
public comp(fs: function[] | iterator): function source
import comp from 'lajure/src/comp.js'
関数を合成します。
Params:
Name | Type | Attribute | Description |
fs | function[] | iterator | 合成したい関数の集合 |
Example:
comp(foo, bar);
// = x => foo(bar(x));
public complement(f: function): function source
import complement from 'lajure/src/complement.js'
引数の関数の戻り値の真偽を逆にした関数を生成します。
Params:
Name | Type | Attribute | Description |
f | function | 真偽を返す関数 |
Example:
complement(isClojurian);
// = Clojurianでなければtrue、Clojurianならばfalseを返す関数
public * concat(xss: *[][] | iterator[]): iterator source
import concat from 'lajure/src/concat.js'
複数の集合を結合します。
Params:
Name | Type | Attribute | Description |
xss | *[][] | iterator[] | 結合したい集合の集合 |
Return:
iterator | 結合された集合のイテレーター |
Example:
concat([1, 2, 3], [4, 5, 6]); // [1, 2, 3, 4, 5, 6]のイテレーターを返す
public condCall(x: *, clauses: *[]): * source
import condCall from 'lajure/src/condCall.js'
値と、条件と関数のペアの集合をとり、条件が真の場合は値を引数に関数を実行した戻り値を返します。条件が偽の場合は値をそのまま返します。 さらに条件と関数のペアがある場合は、条件が真の場合は一つ前の結果を引数にして関数を実行します。条件が儀の場合は、一つ前の処理の結果をそのまま返します。
Params:
Name | Type | Attribute | Description |
x | * | 値 |
|
clauses | *[] | 条件, 関数, 条件, 関数...と続く集合 |
Return:
* | 最後の条件が真なら最後の関数の戻り値、そうでなければ一つ前の関数の戻り値。そうでなければ更に一つ前の関数の戻り値。 |
Example:
return condCall(developer,
developer.isJavaScripter(), raiseSalary);
// = return developer.isJavaScripter() ? raiseSalary(developer) : developer; // 偽の場合のコードの記述が不要になって、便利なはず。
public * conj(coll: *[] | iterator | null, x: *): iterator source
import conj from 'lajure/src/conj.js'
集合の最後に要素を追加し、イテレーターを返します。Clojureのconjとは異なり、コレクションではなくイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
|
x | * | 追加する要素 |
Return:
iterator | 最後に要素が追加された集合のイテレーター |
public * cons(x: *, coll: *[] | iterator | null): iterator source
import cons from 'lajure/src/cons.js'
集合の先頭に要素を追加し、イテレーターを返します。
Params:
Name | Type | Attribute | Description |
x | * | 追加する要素 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 先頭に要素が追加された集合のイテレーター |
Example:
// 無限に続くフィボナッチ数列
functon getFibonacciNumbers(x, y) {
return cons(x, lazySeq(getFibonacciNumbers(y, x + y)));
}
public constantly(x: *): function source
import constantly from 'lajure/src/constantly.js'
指定した引数を返す関数を生成します。
Params:
Name | Type | Attribute | Description |
x | * | 生成した関数が返す戻り値 |
public count(coll: *[] | iterator | null): number source
import count from 'lajure/src/count.js'
集合に含まれる要素の数を返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
public * cycle(coll: *[] | iterator | null): iterator source
import cycle from 'lajure/src/cycle.js'
集合を繰り返した集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | 集合を繰り返した集合のイテレーター |
Example:
cycle([1, 2, 3]); // [1, 2, 3, 1, 2, 3, ...]のイテレーター
public dec(n: number): number source
import dec from 'lajure/src/dec.js'
引数から1を引きます。
Params:
Name | Type | Attribute | Description |
n | number | 数値 |
public * dedupe(coll: *[] | iterator | null): iterator source
import dedupe from 'lajure/src/dedupe.js'
一つ前の要素と値が異なる要素のみの集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | 一つ前の要素と値が異なる要素のみの集合のイテレーター |
Example:
dedupe([1, 2, 3, 3, 3, 1, 1, 4]); // [1, 2, 3, 1, 4]のイテレーター
public * distinct(coll: *[] | iterator | null): iterator source
import distinct from 'lajure/src/distinct.js'
集合から重複した要素を削除したイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | 重複した要素が削除された集合のイテレーター |
Example:
distinct([1, 2, 3, 3, 3, 1, 1, 4]); // [1, 2, 3, 4]のイテレーター
public drop(n: number, coll: *[] | iterator | null): iterator source
import drop from 'lajure/src/drop.js'
集合から先頭n個の要素を削除したイテレーターを返します。
Params:
Name | Type | Attribute | Description |
n | number | 削除する要素の数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 先頭n個の要素が削除された集合のイテレーター |
Example:
drop(2, range()); // [2, 3, 4, ...]のイテレーター
public * dropLast(args: *[]): iterator source
import dropLast from 'lajure/src/dropLast.js'
最後のn個の要素を削除したイテレーターを返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [n, coll]もしくは[coll]。collのみが指定された場合、nは1になります。 |
Return:
iterator | 最後のn個の要素が削除された集合のイテレーター |
Example:
dropLast(2, range(5)); // [0, 1, 2]のイテレーター
dropLast( range(5)); // [0, 1, 2, 3]のイテレーター
public * dropWhile(pred: function, coll: *[] | iterator | null): * source
import dropWhile from 'lajure/src/dropWhile.js'
先頭から続く条件を満たす要素を削除したイテレーターを返します。
Params:
Name | Type | Attribute | Description |
pred | function | 削除する条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
* | 先頭から続く条件を満たす要素が削除されたイテレーター |
Example:
dropWhile(x => x < 2, [0, 1, 2, 3, 2, 1, 0]); // [2, 3, 2, 1, 0]のイテレーター
public every(pred: function, coll: *[] | iterator | null ): boolean source
import every from 'lajure/src/every.js'
集合のすべての要素が条件を満たすか確認します。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
public everyPred(fs: function[]): function source
import everyPred from 'lajure/src/everyPred.js'
引数で指定されるすべての条件を満たすかを確認する関数を生成します。
Params:
Name | Type | Attribute | Description |
fs | function[] | 関数 |
Example:
const isFizz = x => x % 3 === 0;
const isBuzz = x => x % 5 === 0;
const isFizzBuzz = everyPred(isFizz, isBuzz);
isFizzBuzz(15); // true
public ffirst(coll: *[][] | iterator | null): * source
import ffirst from 'lajure/src/ffirst.js'
集合の最初の要素の最初の要素を返します。first(first(xoll))と同じです。
Params:
Name | Type | Attribute | Description |
coll | *[][] | iterator | null | 集合の集合 |
Return:
* | 最初の要素の最初の要素 |
public * filter(pred: function, coll: *[] | iterator | null): iterator source
import filter from 'lajure/src/filter.js'
集合から条件を満たす要素を抽出し、その要素の集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 抽出された要素の集合のイテレーター |
Example:
filter(x => x % 2 === 0, iterate(inc, 1)); // [2, 4, 6, 8, ...]のイテレーター
public first(coll: *[] | iterator): * source
import first from 'lajure/src/first.js'
集合の最初の要素を返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | 集合 |
Return:
* | 最初の要素 |
public flatten(coll: *[][] | iterator | null): * source
import flatten from 'lajure/src/flatten.js'
集合の集合を集合に変換し、そのイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[][] | iterator | null | 集合の集合 |
Return:
* | 集合のイテレーター |
Example:
flatten([1, 2, [3, 4, [5, 6], 7], 8]); // [1, 2, 3, 4, 5, 6, 7, 8]のイテレーター
public fnext(coll: *[] | iterator | null): * source
import fnext from 'lajure/src/fnext.js'
集合の2番目以降の要素の最初の要素(つまり2番目の要素)を返します。first(next(coll))と同じです。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
* | 集合の2番目以降の要素の最初の要素(つまり2番目の要素) |
public fnil(f: function, defaultArgs: *[]): function source
import fnil from 'lajure/src/fnil.js'
引数がnullだった場合に、指定されたデフォルト値に置き換えて実行する関数を生成します。
Params:
Name | Type | Attribute | Description |
f | function | 実行する関数 |
|
defaultArgs | *[] | 引数のデフォルト値 |
public groupBy(f: function, coll: *[] | iterator | null): * source
import groupBy from 'lajure/src/groupBy.js'
集合の要素をグループ単位に分けたマップを返します。
Params:
Name | Type | Attribute | Description |
f | function | 要素に対する操作 |
|
coll | *[] | iterator | null | 集合 |
Return:
* | f(x)をキー、xの配列を値に持つマップ |
Example:
groupBy(x => x % 2 === 0 ? 'even' : 'odd', range(10)); // Map([['even', [0, 2, 4, 6, 8]], ['odd', [1, 3, 5, 7, 9]]]);
public identity(x: *): * source
import identity from 'lajure/src/identity.js'
引数の値をそのまま返します。文法上関数を指定しなければならないのだけどやる処理がない場合に使用してください。
Params:
Name | Type | Attribute | Description |
x | * | 返したい値 |
Return:
* | 引数の値 |
Example:
juxt(identity, reverse)(range(3)]); // [[0, 1, 2]のイテレーター, [2, 1, 0]のイテレーター]
public inc(n: number): number source
import inc from 'lajure/src/inc.js'
引数に1を足します。
Params:
Name | Type | Attribute | Description |
n | number | 数値 |
public * interleave(colls: *[][] | iterator[]): * source
import interleave from 'lajure/src/interleave.js'
1つ目の集合の最初の要素、2つ目の集合の最初の要素……、1つ目の要素の2番目の要素、2つ目の要素の2番目の要素……という集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
colls | *[][] | iterator[] | 集合の集合 |
Return:
* | 集合のイテレーター |
Example:
iterleave([0, 1, 2], [3, 4, 5], [6, 7, 8]); // [0, 3, 6, 1, 4, 7, 2, 5, 8]のイテレーター
public * interpose(sep: *, coll: *[] | iterator | null): iterator source
import interpose from 'lajure/src/interpose.js'
集合の要素の間にセパレーターを挟み込んだ集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
sep | * | セパレーター |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 集合の要素の間にセパレーターが挟み込まれた集合のイテレーター |
Example:
interpose(0, range(1, 5)); // [1, 0, 2, 0, 3, 0, 4]のイテレーター
public isEmpty(coll: *[] | iterator | null): boolean source
import isEmpty from 'lajure/src/isEmpty.js'
集合が空か調べます。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
public isSequencial(x: *): boolean source
import isSequencial from 'lajure/src/isSequencial.js'
イテレーターを取得できるか(イテラブルか)確認します。
Params:
Name | Type | Attribute | Description |
x | * | イテレーターを取得できるか確認する対象 |
public * iterate(f: function, x: *): * source
import iterate from 'lajure/src/iterate.js'
初期値、初期値を引数に関数を呼び出した戻り値、その戻り値を引数に関数を呼び出した戻り値……のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
f | function | 関数 |
|
x | * | 初期値 |
Return:
* | [x, f(x), f(f(x)), f(f(f(x)))...]のイテレーター |
Example:
iterate(inc, 1); // すべての自然数
public juxt(fs: function[]): function source
import juxt from 'lajure/src/juxt.js'
引数で指定した関数群の戻り値の集合へのイテレーターを返す関数を生成します。
Params:
Name | Type | Attribute | Description |
fs | function[] | 関数 |
Example:
const [x, iter] = juxt(first, next)([1, 2, 3]);
// x == 1
// iter == [2, 3]のイテレーター
public * keep(f: function, coll: *[] | iterator | null): iterator source
import keep from 'lajure/src/keep.js'
集合の要素を引数に取る関数を実行した結果がnullでない場合の集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
f | function | 集合の要素を引数に取る関数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 関数の実行結果がnullでない場合の集合のイテレーター |
Example:
keep(x => x > 0 ? x * 2 : null, [-9 0 29 -7 45 3 -8]); // [58, 90, 6]のイテレーター
public keepIndexed(f: function, coll: *[] | iterator | null): iterator source
import keepIndexed from 'lajure/src/keepIndexed.js'
インデックスと集合の要素を引数に取る関数を実行した結果がnullでない場合の集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
f | function | インデックスと集合の要素を引数に取る関数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 関数の実行結果がnullでない場合の集合のイテレーター |
Example:
keepIndexed((i, x) => x > 0 ? i : null, [-9 0 29 -7 45 3 -8]); // [2, 4, 5]のイテレーター
public last(coll: *[] | iterator | null): * source
import last from 'lajure/src/last.js'
集合の最後の要素を返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
* | 集合の最後の要素 |
public lazySeqFn(f: function): * source
import lazySeqFn from 'lajure/src/lazySeqFn.js'
イテレーターが必要となったときまで、関数の実行を遅延します。lazySeqマクロを使用すれば、関数呼び出しをそのまま記述できます。
Params:
Name | Type | Attribute | Description |
f | function | イテレーターまたはnullを返す関数 |
Return:
* | 関数を遅延実行するイテラブル |
Example:
// 無限に続くフィボナッチ数列
functon getFibonacciNumbers(x, y) {
return cons(x, lazySeq(getFibonacciNumbers(y, x + y)));
// = return cons(x, lazySeqFn(() => getFibonacciNumbers(y, x + y)));
}
public * map(f: *, colls: ...*) source
import map from 'lajure/src/map.js'
Params:
Name | Type | Attribute | Description |
f | * | ||
colls | ...* |
public mapIndexed(f: function, coll: *[] | iterator | null): iterator source
import mapIndexed from 'lajure/src/mapIndexed.js'
インデックスと集合の要素を引数に取る関数を実行した結果の集合のイテレーターを返します。map(f, range(), coll)と同じです。
Params:
Name | Type | Attribute | Description |
f | function | インデックスと集合の要素を引数に取る関数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 関数の実行結果の集合のイテレーター |
Example:
map((i, e) => [i, e.favoriteLanguage()], getEmployees()); // インデックスと好きな言語の配列のシーケンス
public mapcat(f: function, colls: *[][] | iterator[]): iterator source
import mapcat from 'lajure/src/mapcat.js'
mapした結果をconcatします。apply(concat, map(f, coll))と同じです。
Params:
Name | Type | Attribute | Description |
f | function | 集合の要素に対して実行する関数 |
|
colls | *[][] | iterator[] | 集合 |
Return:
iterator | 関数の戻り値をconcatした集合のイテレーター |
Example:
mapcat(e => e.canUseLanguages(), getEmployees()); // 社員が使用できる言語の集合。イテレーターのイテレーターにならずに、イテレーターになります
public max(xs: *[]): * source
import max from 'lajure/src/max.js'
引数の中で最大の値を返します。
Params:
Name | Type | Attribute | Description |
xs | *[] | 値の集合 |
Return:
* | 最大の値 |
public maxKey(k: funciton, xs: *[]): * source
import maxKey from 'lajure/src/maxKey.js'
k(x)が最大のxを返します。
Params:
Name | Type | Attribute | Description |
k | funciton | 比較対象のキーを取得する関数 |
|
xs | *[] | 値の集合 |
Return:
* | k(x)が最大のx |
Example:
maxKey(e => e.getSalary(), a, b, c); // 最も給料が高い社員
public maxKey(k: funciton, xs: *[]): * source
import maxKey from 'lajure/src/minKey.js'
k(x)が最小のxを返します。
Params:
Name | Type | Attribute | Description |
k | funciton | 比較対象のキーを取得する関数 |
|
xs | *[] | 値の集合 |
Return:
* | k(x)が最小のx |
Example:
minKey(e => e.getSalary(), a, b, c); // 最も給料が低い社員
public memoize(f: function): function source
import memoize from 'lajure/src/memoize.js'
関数をメモ化します。
Params:
Name | Type | Attribute | Description |
f | function | 関数 |
public min(xs: *[]): * source
import min from 'lajure/src/min.js'
引数の中で最小の値を返します。
Params:
Name | Type | Attribute | Description |
xs | *[] | 値の集合 |
Return:
* | 最小の値 |
public next(coll: *[] | iterator | null): iterator | null source
import next from 'lajure/src/next.js'
集合の2番目の要素から最後の要素までのイテレーターを返します。集合の要素数が2未満の場合は、nullを返します。空集合のイテレーターが必要な場合は、restを使用してください。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | null | 集合の2番目の要素から最後の要素までのイテレーター、またはnull |
public nfirst(coll: *[] | iterator | null): iterator | null source
import nfirst from 'lajure/src/nfirst.js'
集合の最初の要素の2番目の要素から最後の要素までのイテレーターを返します。next(first(coll))と同じです。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | null | 集合の最初の要素の2番目の要素から最後の要素までのイテレーター |
public nnext(coll: *[] | iterator | null): iterator | null source
import nnext from 'lajure/src/nnext.js'
集合の2番目以降の要素の2番目以降の要素(つまり3番目以降の要素)を返します。next(next(coll))と同じです。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | null | 集合の最初の要素の2番目の要素から最後の要素までのイテレーター |
public notAny(pred: function, coll: *[] | iterator | null): boolean source
import notAny from 'lajure/src/notAny.js'
集合の要素の中に、条件を満たすものが1つもないことを確認します。someの反対です。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
public notEvery(pred: function, coll: *[] | iterator | null): boolean source
import notEvery from 'lajure/src/notEvery.js'
集合の要素の中に、条件を満たさないものがあるか確認します。everyの反対です。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
public nth(coll: *[] | iterator | null, n: number): * | null source
import nth from 'lajure/src/nth.js'
集合のn番目の要素を取得します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
|
n | number | 何番目の要素を取得したいか |
Return:
* | null | n番目の要素。要素が存在しない場合はnull |
public nthnext(coll: *[] | iterator | null, n: number): iterator | null source
import nthnext from 'lajure/src/nthnext.js'
集合のn番目以降のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
|
n | number | 何番目以降のデータを取得するか |
Return:
iterator | null | 集合のn番目以降のイテレーター。集合の要素数がnよりも小さい場合はnull |
public nthrest(coll: *[] | iterator | null, n: number): iterator | null source
import nthrest from 'lajure/src/nthrest.js'
集合のn番目以降のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
|
n | number | 何番目以降のデータを取得するか |
Return:
iterator | null | 集合のn番目以降のイテレーター |
public partial(f: function, args: *[]): function source
import partial from 'lajure/src/partial.js'
関数に引数を部分適用します。
Params:
Name | Type | Attribute | Description |
f | function | 関数 |
|
args | *[] | 引数 |
Example:
const multiples = (x) => iterate(y => y + x, x); // xの倍数のイテレーターを返す関数
const multiplesOf5 = partial(multiples, 5); // [5, 10, 15, 20, 25...]のイテレーターを返す関数
public * partition(args: *[]): iterator source
import partition from 'lajure/src/partition.js'
集合を分割します。分割した余りは返されません。
Params:
Name | Type | Attribute | Description |
args | *[] | [n、step、pad、coll]。nは要素数、stepは分割する位置(省略した場合はnと同じ)、padは要素が不足した場合に追加する値(省略した場合はnull)、collは集合。 |
Return:
iterator | 分割された集合のイテレーター |
Example:
partition(3, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [3, 4, 5]]のイテレーター
partition(3, 4, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [4, 5, 6]]のイテレーター
partition(3, 2, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [2, 3, 4], [4, 5, 6]]のイテレーター
partition(3, 3, [0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [3, 4, 5], [6, 7, 0]]のイテレーター
public * partitionAll(args: *[]): iterator source
import partitionAll from 'lajure/src/partitionAll.js'
集合を分割します。partitionとは異なり、分割した余りも返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [n、step、coll]。nは要素数、stepは分割する位置(省略した場合はnと同じ)、collは集合。 |
Return:
iterator | 分割された集合のイテレーター |
Example:
partition(3, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [3, 4, 5], [7]]のイテレーター
partition(3, 4, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [4, 5, 6]]のイテレーター
partition(3, 2, [0, 1, 2, 3, 4, 5, 6, 7]); // [[0, 1, 2], [2, 3, 4], [4, 5, 6], [6, 7]]のイテレーター
public * partitionBy(f: function, coll: *[] | iterator | null): iterator source
import partitionBy from 'lajure/src/partitionBy.js'
指定した関数の戻り値が変更になるたびに、集合を分割します。
Params:
Name | Type | Attribute | Description |
f | function | 関数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 分割された集合のイテレーター |
Example:
partitionBy(x => x % 2 === 0, [1, 1, 1, 2, 2, 3, 3, 4]); // [[1, 1, 1], [2, 2], [3, 3], [4]]のイテレーター
public pipe(fs: function[]): function source
import pipe from 'lajure/src/pipe.js'
最初の関数の戻り値を入力にして次の関数を実行、その戻り値を入力にしてその次の関数を実行……のように、関数をパイプで接続して実行する関数を生成します。
Params:
Name | Type | Attribute | Description |
fs | function[] | 関数 |
public randNth(coll: *[] | iterator | null): * source
import randNth from 'lajure/src/randNth.js'
要素を1つランダムに抽出します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
* | ランダムに抽出された要素 |
public randomSample(prob: number, coll: *[] | iterator | null): iterator source
import randomSample from 'lajure/src/randomSample.js'
各要素を確率probで抽出します。一般に、抽出される要素の数がcount(coll) * probと一致するとは限りません。 n個必要で順序が安定でなくても良い場合は、take(n, shuffle(coll))を使用してください。
Params:
Name | Type | Attribute | Description |
prob | number | 要素を抽出する確率 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 抽出された集合のイテレーター |
Example:
randomSample(0.5, [1, 2, 3, 4, 5]); // [1, 3, 5]や[1, 2]や[4]などのイテレーター
public * range(args: number[]): iterator source
import range from 'lajure/src/range.js'
範囲を表現するイテレーターを返します。
Params:
Name | Type | Attribute | Description |
args | number[] | []か[end]、[start, end]、[start, end step]のどれか。startのデフォルト値は0、stepのデフォルト値は1、endのデフォルト値は無限 |
Return:
iterator | 範囲のイテレーター |
Example:
range(); // [0, 1, 2, 3, ...]のイテレーター
range(5); // [0, 1, 2, 3, 4]のイテレーター
range(1, 5); // [1, 2, 3, 4]のイテレーター
range(1, 5, 2); // [1, 3]のイテレーター
public reduce(args: *[]): * source
import reduce from 'lajure/src/reduce.js'
畳み込みます。f(f(f(init, coll[0]), coll[1]), coll[2])...の結果を返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [f, init, coll]か[f, coll]のどちらか。 |
Return:
* | 畳み込まれた値 |
Example:
reduce((acc, x) => acc + x, xs); // xsの合計
public reduced(x: *): object source
import reduced from 'lajure/src/reduced.js'
reduceを途中で終了させます。
Params:
Name | Type | Attribute | Description |
x | * | reduceの戻り値となる値 |
Example:
reduce((acc, x) => x > 10 ? acc : acc + x, range(1, 101)); // 55
reduce((acc, x) => acc + x, range(1, 101)); // 5050;
public * reductions(args: *[]): iterator source
import reductions from 'lajure/src/reductions.js'
reduceの途中経過も含めて、イテレーターで返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [f, init, coll]か[f, coll]のどちらか。 |
Return:
iterator | 途中経過も含めたreduceの結果のイテレーター |
Example:
reduce((acc, x) => acc + x, [1, 2, 3]); // [1, 3, 6]のイテレーター
public remove(pred: function, coll: *[] | iterator | null): iterator source
import remove from 'lajure/src/remove.js'
条件を満たす要素を除いた集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 条件を満たす要素が覗かれた集合のイテレーター |
public * repeat(args: *[]): iterator source
import repeat from 'lajure/src/repeat.js'
値を繰り返す集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [n, x]か[x] |
Return:
iterator | 集合のイテレーター |
Example:
repeat( 0); // [0, 0, 0...]のイテレーター
repeat(3, 0); // [0, 0, 0]のイテレーター
public * repeatedly(args: *[]): iterator source
import repeatedly from 'lajure/src/repeatedly.js'
関数を繰り返して実行し、その結果を返します。
Params:
Name | Type | Attribute | Description |
args | *[] | [n, f]か[f] |
Return:
iterator | 集合のイテレーター |
Example:
repeatedly( constantly(0)); // [0, 0, 0...]のイテレーター
repeatedly(3, constantly(0)); // [0, 0, 0]のイテレーター
public replace(smap: Map, coll: *[] | iterator | null): iterator source
import replace from 'lajure/src/replace.js'
集合の要素をマップの値で置き換えます。
Params:
Name | Type | Attribute | Description |
smap | Map | 要素の置き換え規則のマップ |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 置き換えられた集合のイテレーター |
Example:
replace(new Map([[0, 'zero'], [1, 'one'], [2, 'two']]), range(3)); // ['zero', 'one', 'two']のイテレーター
public rest(coll: *[] | iterator | null): iterator source
import rest from 'lajure/src/rest.js'
集合の2番目の要素から最後の要素までのイテレーターを返します。集合の要素数が2未満の場合は、空集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | 集合の2番目の要素から最後の要素までのイテレーター |
public reverse(coll: *[] | iterator | null): iterator source
import reverse from 'lajure/src/reverse.js'
集合の要素を逆順にします。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | 逆順の集合のイテレーター |
public rseq(coll: *[]): iterator | null source
import rseq from 'lajure/src/rseq.js'
配列を逆順に辿るイテレーターを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | 配列 |
Return:
iterator | null | イテレーター。配列が空の場合はnull |
public second(coll: *[] | iterator | null): * source
import second from 'lajure/src/second.js'
2番目の要素を抽出します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
* | 2番目の要素 |
public seq(coll: *[] | iterator | null): iterator | null source
import seq from 'lajure/src/seq.js'
集合からイテレーターを取得します。集合が空の場合はnullを返します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | null | イテレーター |
public sequence(coll: *[] | iterator | null): iterator source
import sequence from 'lajure/src/sequence.js'
集合からイテレーターを取得します。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | イテレーター |
public * shuffle(coll: *[] | iterator | null): iterator source
import shuffle from 'lajure/src/shuffle.js'
集合をシャッフルします。
Params:
Name | Type | Attribute | Description |
coll | *[] | iterator | null | 集合 |
Return:
iterator | シャッフルされた集合のイテレーター |
public some(pred: function, coll: *[] | iterator | null): * | null source
import some from 'lajure/src/some.js'
集合の中に条件を満たすものがあるか確認します。条件は関数で指定し、最初に真になった関数の戻り値を返します。最後まで真にならなかった場合は、nullを返します。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
* | null | 最初に真となった関数の戻り値。すべてが偽だった場合はnull。 |
public someCall(x: *, fs: function[] | iterator): * source
import someCall from 'lajure/src/someCall.js'
指定された引数を使用して最初の関数を呼び出し、その結果を引数に次の関数を呼び出します。関数がnullを返した場合は、そこで処理を完了します。 引数にコードの一部を使用したい場合は、tSomeCallマクロを使用してください。
Params:
Name | Type | Attribute | Description |
x | * | 最初の関数の引数 |
|
fs | function[] | iterator | 順番に呼び出す関数の集合 |
Return:
* | 最後、もくくはnullを返した関数の戻り値 |
Example:
someCall(employee, // 社員の
employee => employee.getComputer(), // 所有するコンピューターの
computer => computer.getSoftwareVersion('Node.js')); // Node.jsのバージョンを調べます。
// computerがnullなら、3行目は実行されないでnullが戻ります。
public someFn(fs: function[]): function source
import someFn from 'lajure/src/someFn.js'
引数で指定される条件を一つでも満たすかを確認する関数を生成します。
Params:
Name | Type | Attribute | Description |
fs | function[] | 関数 |
public sort(args: *[]): iterator source
import sort from 'lajure/src/sort.js'
ソートします。
Params:
Name | Type | Attribute | Description |
args | *[] | [comp, coll]か[coll]。compが省略された場合は<演算子。 |
Return:
iterator | ソートされた集合のイテレーター |
Example:
sort( [2, 3, 1]); // [1, 2, 3]のイテレーター
sort((x, y) => x > y, [2, 3, 1]); // [3, 2, 1]のイテレーター
public sortBy(args: *[]): iterator source
import sortBy from 'lajure/src/sortBy.js'
関数の戻り値でソートします。
Params:
Name | Type | Attribute | Description |
args | *[] | [keyfn, comp, coll]か[keyfn, coll]。compが省略された場合は<演算子。 |
Return:
iterator | ソートされた集合のイテレーター |
Example:
sortBy(x => x.getAge(), xs); // 年齢順でソート
public splitAt(n: number, coll: *[] | iterator | null): iterator[] source
import splitAt from 'lajure/src/splitAt.js'
指定した箇所で集合を分割します。
Params:
Name | Type | Attribute | Description |
n | number | 分割する場所 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator[] | 分割された集合のイテレーターの配列 |
Example:
splitAt(2, [1, 2, 3, 4, 5]); // [[1, 2]のイテレーター, [3, 4, 5]のイテレーター]
public splitWith(pred: function, coll: *[] | iterator | null): iterator[] source
import splitWith from 'lajure/src/splitWith.js'
先頭から続く指定した条件を満たす要素の集合tと、そうでない要素の集合に分割します。[takeWhile(pred, coll), dropWhile(pred, coll)]です。
Params:
Name | Type | Attribute | Description |
pred | function | 条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator[] | 分割された集合のイテレーターの配列 |
Example:
splitWith(x => x < 3, [1, 2, 3, 2, 1]); // [[1, 2]のイテレーター, [3, 2, 1]のイテレーター]
public * take(n: number, coll: *[] | iterator | null): iterator source
import take from 'lajure/src/take.js'
集合の先頭n個の要素のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
n | number | 取得する要素の数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 先頭n個の要素の集合のイテレーター |
Example:
take(3, range()); // [0, 1, 2]のイテレーター
public takeLast(n: number, coll: *[] | iterator | null): iterator source
import takeLast from 'lajure/src/takeLast.js'
集合の末尾n個の要素のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
n | number | 取得する要素の数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 末尾n個の要素の集合のイテレーター |
Example:
takeLast(3, range(10)); // [7, 8, 9]のイテレーター
public * takeNth(n: number, coll: *[] | iterator | null): iterator source
import takeNth from 'lajure/src/takeNth.js'
n個単位に要素を抽出した集合のイテレーターを返します。
Params:
Name | Type | Attribute | Description |
n | number | 取得する要素の場所 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | n番目の要素、n 2番目の要素、n 3番目の要素...の集合のイテレーター |
Example:
takeNth(2, range()); [0, 2, 4, 6, 8, 10...]のイテレーター
public * takeWhile(pred: function, coll: *[] | iterator | null): iterator source
import takeWhile from 'lajure/src/takeWhile.js'
先頭から続く、条件を満たす要素を抽出したイテレーターを返します。
Params:
Name | Type | Attribute | Description |
pred | function | 抽出する条件 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | 先頭から続く条件を満たす要素が抽出されたイテレーター |
Example:
takeWhile(x => x < 2, [0, 1, 2, 3, 2, 1, 0]); // [0, 1]のイテレーター
public tee(n: number, coll: *[] | iterator | null): iterator source
import tee from 'lajure/src/tee.js'
イテレーターを複数に分けます。
Params:
Name | Type | Attribute | Description |
n | number | イテレーターの個数 |
|
coll | *[] | iterator | null | 集合 |
Return:
iterator | イテレーターの集合 |