boostorg / boostorg/hof

compress versus fold

Open
#62 29 comments 0 reactions 0 assignees View on GitHub
document enhancement
Dominant language
C++
Stars
509
Forks
94
PR merge metrics
No merged PRs in 30d

Description

There are two variants of fold, left associative versus right.

What about naming them `fold_left` and `fold_right`?

Given an adaptor that results in a variadic function as `compress`

compress:: F A -> (B.... -> A)

we could define it by using a function having a tuple as parameter

```
compress(f, z)(xs...) = fold(f, z, forward_as_tuple(xs...))
```

I believe that we have already this kind of fold fuctions in Hana.

So given

```
fold: F A H -> A
```

`partial(fold, F, A)` would almost behave like compress except that `partial(fold, F A)` takes a tuple as parameter and compress takes a variadic number of arguments. So we can see compress something like

```
compress(f, a) = compose(partial(fold, f, a), forward_as_tuple)
```

I'm not saying that compress is not useful, even if the name has not too much relation to what is behind the scenes. I would say that it could be a useful shortcut when the user doesn't has already a sequence or a tuple.

Of course, in C++ we don't want to pay more than needed, so the implementation should be more efficient than using the right hand side.

It would be fanny to have some performance measures. This is micro-benchmarking, but having the figures would help the user to understand the trade-offs.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.