Skip to content

Commit 2a12ed3

Browse files
add R.searchUntil
1 parent aba4e75 commit 2a12ed3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

scriptum.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6587,7 +6587,7 @@ R.searchAll = rx => s =>
65876587
Array.from(s.matchAll(rx)).map(ix => ix.index);
65886588

65896589

6590-
R.searchAllWith = p => rx => s =>
6590+
R.searchAllWith = ({p, rx}) => s =>
65916591
R.matchAllWith({p, rx}) (s).map(ix => ix.index);
65926592

65936593

@@ -6602,7 +6602,7 @@ R.searchFirst = rx => s => {
66026602
};
66036603

66046604

6605-
R.searchFirstWith = p => rx => s => {
6605+
R.searchFirstWith = ({p, rx}) => s => {
66066606
for (const ix of s.matchAll(rx))
66076607
if (p(ix)) return [ix.index];
66086608

@@ -6617,7 +6617,7 @@ R.searchLast = rx => s => {
66176617
};
66186618

66196619

6620-
R.searchLastWith = p => rx => s => {
6620+
R.searchLastWith = ({p, rx}) => s => {
66216621
const xs = R.matchAllWith({p, rx}) (s);
66226622
if (xs.length === 0) return [];
66236623
else return [xs[xs.length - 1].index];
@@ -6626,7 +6626,7 @@ R.searchLastWith = p => rx => s => {
66266626

66276627
// negative indices are processed relative to the end
66286628

6629-
R.searchNth = (rx, n) => s => {
6629+
R.searchNth = ({n, rx}) => s => {
66306630
const xs = s.matchAll(rx);
66316631
if (n - 1 >= xs.length) return [];
66326632
else if (n >= 0) return [xs[n - 1].index];
@@ -6636,14 +6636,22 @@ R.searchNth = (rx, n) => s => {
66366636

66376637
// negative indices are processed relative to the end
66386638

6639-
R.searchNthWith = p => (rx, n) => s => {
6639+
R.searchNthWith = p => ({n, rx}) => s => {
66406640
const xs = R.matchAllWith({p, rx}) (s);
66416641
if (n - 1 >= xs.length) return [];
66426642
else if (n >= 0) return [xs[n - 1].index];
66436643
else return [xs.slice(n) [0].index];
66446644
};
66456645

66466646

6647+
// negative indices are processed relative to the end
6648+
6649+
R.searchNth = ({n, rx}) => s => {
6650+
const xs = s.matchAll(rx);
6651+
return xs.slice(0, n);
6652+
};
6653+
6654+
66476655
//█████ Matching ██████████████████████████████████████████████████████████████
66486656

66496657

0 commit comments

Comments
 (0)