Is there a standard function that combines take() and popFrontExactly()

Dukc ajieskola at gmail.com
Mon Dec 14 14:16:41 UTC 2020


On Friday, 11 December 2020 at 19:07:23 UTC, realhet wrote:
> I've just made this unicode wordreplacer function working, but 
> It seems not too nice and functional-ish.
> Are there ways to make it more simple?


To answer the title, yes there is:

```
foreach(isWord, len; str.map!fun.group){
    auto act = (&src).refRange.take(len).text;

    res.put(isWord && act==from ? to : act);
}
```

But personally I think it does not pay to try to be more 
functional than what this snippet already is. The most important 
thing is that the program is functional on the high level. This 
means avoiding globals and static variables (`pure` may help), 
big monolithic functions, god classes and functions which get 
needless info by their parameters. Being functional in the low 
level is secondary and not always worth it.


More information about the Digitalmars-d-learn mailing list