sequences.generalizations: adding nmap-reduce.
parent
13db482b7f
commit
4dd3511a40
|
@ -110,6 +110,10 @@ HELP: nproduce-as
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "exemplar..." { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "exemplar..." { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
|
||||||
{ $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
{ $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
||||||
|
|
||||||
|
HELP: nmap-reduce
|
||||||
|
{ $values { "map-quot" quotation } { "reduce-quot" quotation } { "n" integer } }
|
||||||
|
{ $description "A generalization of " { $link map-reduce } " that can be applied to any number of sequences." } ;
|
||||||
|
|
||||||
ARTICLE: "sequences.generalizations" "Generalized sequence words"
|
ARTICLE: "sequences.generalizations" "Generalized sequence words"
|
||||||
"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of various sequence operations."
|
"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of various sequence operations."
|
||||||
{ $subsections
|
{ $subsections
|
||||||
|
|
|
@ -132,3 +132,7 @@ D4d$
|
||||||
|
|
||||||
[ { 10 8 6 4 2 } { 9 7 5 3 1 } ]
|
[ { 10 8 6 4 2 } { 9 7 5 3 1 } ]
|
||||||
[ 10 nproduce-test ] unit-test
|
[ 10 nproduce-test ] unit-test
|
||||||
|
|
||||||
|
{ 45 } [
|
||||||
|
{ 1 2 3 } { 4 5 6 } { 7 8 9 } [ + + ] [ + ] 3 nmap-reduce
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -42,6 +42,9 @@ MACRO: nmin-length ( n -- )
|
||||||
dup 1 - [ min ] n*quot
|
dup 1 - [ min ] n*quot
|
||||||
'[ [ length ] _ napply @ ] ;
|
'[ [ length ] _ napply @ ] ;
|
||||||
|
|
||||||
|
: nnth ( n seq... n -- )
|
||||||
|
[ nth ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
||||||
|
|
||||||
: nnth-unsafe ( n seq... n -- )
|
: nnth-unsafe ( n seq... n -- )
|
||||||
[ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
[ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
||||||
|
|
||||||
|
@ -112,3 +115,9 @@ MACRO: (ncollect) ( n -- )
|
||||||
|
|
||||||
: nproduce ( pred quot n -- seq... )
|
: nproduce ( pred quot n -- seq... )
|
||||||
[ { } swap dupn ] keep nproduce-as ; inline
|
[ { } swap dupn ] keep nproduce-as ; inline
|
||||||
|
|
||||||
|
MACRO: nmap-reduce ( map-quot reduce-quot n -- quot )
|
||||||
|
-rot dupd compose [ over ] dip over '[
|
||||||
|
[ [ first ] _ napply @ 1 ] _ nkeep
|
||||||
|
_ _ (neach) (each-integer)
|
||||||
|
] ;
|
||||||
|
|
Loading…
Reference in New Issue