of sift-values and use the new one.
[ [ drop f ] unless ] 2map ;
: sift-children ( seq flags -- seq' )
- zip [ nip ] assoc-filter keys ;
+ zip sift-values keys ;
: until-fixed-point ( ... #recursive quot: ( ... node -- ... ) -- ... )
over label>> t >>fixed-point drop
: jis>ch ( jis tuple -- string ) assoc>> at replacement-char or ;
: make-jis ( filename -- jis )
- flat-file>biassoc [ nip ] assoc-filter jis boa ;
+ flat-file>biassoc sift-values jis boa ;
"vocab:io/encodings/shift-jis/CP932.txt"
make-jis windows-31j-table set-global
: define-math-ops ( op -- )
{ fixnum bignum float }
[ [ dup 3array ] [ swap ?lookup-method ] 2bi ] with { } map>assoc
- [ nip ] assoc-filter
+ sift-values
[ def>> ] assoc-map
[ nip length 1 = ] assoc-filter
[ first ] assoc-map % ;
M: not-class substitute [ <not-class> ] bi@ answer ;
: assoc-answer ( table question answer -- new-table )
- '[ _ _ substitute ] assoc-map
- [ nip ] assoc-filter ;
+ '[ _ _ substitute ] assoc-map sift-values ;
: assoc-answers ( table questions answer -- new-table )
'[ _ assoc-answer ] each ;
[ "no-def-strip" word-prop not ] filter
[ [ ] >>def drop ] each ;
-: sift-assoc ( assoc -- assoc' ) [ nip ] assoc-filter ;
-
: strip-word-props ( stripped-props words -- )
"Stripping word properties" show
swap '[
[
- [ drop _ member? not ] assoc-filter sift-assoc
+ [ drop _ member? not ] assoc-filter sift-values
>alist f like
] change-props drop
] each ;
commands values [
[
commands>>
- [ drop ] assoc-filter
+ sift-keys
[ '[ _ invoke-command ] swap ,, ] assoc-each
] each
] H{ } make ;
[ get-interpolated '[ _ swap @ [ ?present 2array ] dip ] ]
[ 2array '[ _ swap ] ] if ;
-: filter-nulls ( assoc -- newassoc )
- [ nip ] assoc-filter ;
-
: interpolate-attrs ( attrs -- quot )
[
[ [ interpolate-attr ] { } assoc>map [ ] join ]
[ assoc-size ] bi
- '[ @ _ swap [ narray filter-nulls <attrs> ] dip ]
+ '[ @ _ swap [ narray sift-values <attrs> ] dip ]
] when-interpolated ;
: interpolate-tag ( tag -- quot )
assoc-any?
assoc-all?
}
+"Removing empty keys or values:"
+{ $subsections
+ sift-keys
+ sift-values
+}
"Mapping between assocs and sequences:"
{ $subsections
map>assoc
{ $values { "assoc1" assoc } { "assoc2" assoc } { "?" boolean } }
{ $description "Tests if " { $snippet "assoc2" } " contains all key/value pairs of " { $snippet "assoc1" } "." } ;
+HELP: sift-keys
+{ $values { "assoc" assoc } { "assoc'" "a new assoc" } }
+{ $description "Outputs an assoc removing keys that are " { $link f } "." } ;
+
+HELP: sift-values
+{ $values { "assoc" assoc } { "assoc'" "a new assoc" } }
+{ $description "Outputs an assoc removing values that are " { $link f } "." } ;
+
HELP: assoc=
{ $values { "assoc1" assoc } { "assoc2" assoc } { "?" boolean } }
{ $description "Tests if two assocs contain the same entries. Unlike " { $link = } ", the two assocs may be of different types." }
[ 1 ] [ "a" { H{ { "a" 1 } } H{ { "b" 2 } } } assoc-stack ] unit-test
[ 2 ] [ "b" { H{ { "a" 1 } } H{ { "b" 2 } } } assoc-stack ] unit-test
[ f ] [ "c" { H{ { "a" 1 } } H{ { "b" 2 } } } assoc-stack ] unit-test
+
+
+{
+ { { 1 f } }
+} [
+ { { 1 f } { f 2 } } sift-keys
+] unit-test
+
+{
+ { { f 2 } }
+} [
+ { { 1 f } { f 2 } } sift-values
+] unit-test
\ No newline at end of file
assoc-each
] [ drop ] 2bi ; inline
+: sift-keys ( assoc -- assoc' )
+ [ drop ] assoc-filter ; inline
+
+: sift-values ( assoc -- assoc' )
+ [ nip ] assoc-filter ; inline
+
: assoc-partition ( ... assoc quot: ( ... key value -- ... ? ) -- ... true-assoc false-assoc )
[ (assoc-each) partition ] [ drop ] 2bi
[ assoc-like ] curry bi@ ; inline
: assoc-harvest ( assoc -- assoc' )
[ nip empty? not ] assoc-filter ; inline
-: assoc-sift ( assoc -- assoc' )
- [ nip ] assoc-filter ; inline
-
: deep-at ( assoc seq -- value/f )
[ swap at ] each ; inline