Using Invisibles To Opt Out of Functions In a Chain

One idea for using invisibles is to chain functions where you make some functions disappear from the chain if they're not needed.

Imagine an image processor where you apply sequential effects but only the ones specify as refinements.

imagemagick: func [ data 
    /monochrome
    /sharpen
    /blur
    /pixelise
][
    ... code ..
    sharpen: if sharpen [:sharpenf] [:nihil]
    blur: if blur [:blurf] [:nihil]
    pixelise: if pixelize [:pixelf] [:nihil]

    return sharpen blur pixelise data
]

imagemagick/sharpen imagedata

...giving a much cleaner look. If the refinements are absent, the functions just disappear.

1 Like

This is a creative idea... and I think this sort of creativity is what makes the language fun... having so many different ways to attack problems!

But in this particular case, you could actually use CHAIN to build the composite function, and it might be more obvious:

imagemagick: func [
    data 
    /monochrome
    /sharpen
    /blur
    /pixelise
][
     ... code ..
    return run chain reduce [
        if sharpen [:sharpenf]
        if blur [:blurf]
        if pixelize [:pixelf]
    ] data
]