Hi, Joel,

> 
> > Nor does the technique generalize:
> >
> >         mapper: func ['f] [func [block] compose [foreach element
> >         block [(f)
> > element]]]
> 
>   Sure it does, with one little difference:
> 
>   mapper: func ['f][func [block] compose/deep [
>       foreach element block [(f) element]]
>   ]
> 
>         l: mapper (func [x][prin odd? x])
>         l [1 2 3 4 5]
>         truefalsetruefalsetrue
> 

My experience with other languages leads me to want a 'map that can
take an argument function, returning a function which can be applied
to a block to yield a block of (corresponding) results, as in
(HYPOTHETICAL):

    >> map: ; MISSING (I have no idea at this point)
    >> map-odd: map odd?
    >> map-odd [1 2 3 4 5]
    == [true false true false true]

Could someone (Jeff?) supply the definition for 'map missing above?

-jn-

Here you are:

map: func [
    f [any-function!]
    ] [
    func [
        blk [block!]
        /local result
        ] [
        result: copy []
        foreach x blk [
            append/only result do compose [(:f) x]
            ]
        ]
    ]

;Example:
>> mapodd: map :odd?
>> mapodd [1 2 3 4 5]
== [true false true false true]

Ladislav

Reply via email to