red / REP

Red Enhancement Process
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

WISH: Support MAP! in REMOVE-EACH #93

Open rebolek opened 3 years ago

rebolek commented 3 years ago

foreach supports map! however remove-each does not and for bulk key removal foreach + remove/key combo must be used.

greggirwin commented 3 years ago

How do you see it working? Maps are unordered, so the key you want to remove has to be implicit somehow.

Oldes commented 3 years ago

Related R3's request: https://www.curecode.org/rebol3/ticket.rsp?id=806 @greggirwin maybe working like this:

>> remove-each [key val] #(a 1 "b" 2 c #[none] d: 3) [any [string? key none? val]]
== #(
    a: 1
    d: 3
)

in the same way how is possible to do:

>> foreach [key val] #(a 1 "b" 2 c #[none] d: 3) [print [key "is" val]]
a is 1
b is 2
c is none
d is 3
greggirwin commented 3 years ago

I'm happy for people to play with it and comment.

remove-each_map: func ['word [block!] data [map!] body [block!]][
    foreach [key val] data [
        if do body [remove/key data key]
    ]
    data
]

The R/S today doesn't use the words when remove-each-next call is made, so we'd need a map! version of that. I don't see where remove-each-init is called at all in the code base. @dockimbel is that dead code now?

rebolek commented 3 years ago

Thanks @Oldes that's exactly what I meant.