Dyalog APL: How to filter an array like filter()

I need to filter out from the array (namespaces) all values that do not fulfil the required condition: field 'status' = 'TRADING'

I use this variant


However, it returns every row in the wrapper, and I want clean rows

      tmpSymbols[1] ⍝ I have
││ #.[JSON object].[JSON object] ││

      tmpSymbolsT[1] ⍝ I need like this
#.[JSON object].[JSON object]

How to do it?


  • The problem here is that you filter each (¨) object separately, rather than filtering the entire collection.

    (By the way, you also have an unnecessary commute () which doesn't do anything in this context.)

    So, you really want something along the lines of tmpSymbols←{(⍵.status≡'TRADING')⌿⍵}tmpSymbolsT but now ⍵.status is a vector (list) of statuses, which of course won't match () the single status 'TRADING'. You have a few options for fixing this:

    1. ⍵.status≡¨⊂'TRADING' uses an explicit each and encloses () the single status so it is used for every comparison.
    2. 'TRADING'∘≡¨⍵.status binds () the single status to the match function, thus deriving an "is trading" function, which is then applied to each status.
    3. ⍵.status∊⊂'TRADING' which encloses the single status and checks all the statuses for which ones are a member of () the array of a single status.

    Here is an example of code that does what you want:

    #.[JSON object].[JSON object]