Comments (5)
i disagree. First, we don't have a fold
, we have foldl
and foldr
. foldl
folds the list from the left with the provided accumulator, as opposed to foldr
which folds from the right. foldl
is the same behavior as reduce
. foldl
without an initial accumulator, i.e. using the head of the list, is sometimes called foldl1
, and it's my POV that it should not be in the library, because of the problem of deciding what the behavior is when you call foldl1
with an empty list. Since it is so easy to implement foldl1
, I argue it is best to leave its problems out of the library.
from ramda.
I wasn't aware that "fold" was something other than assumed shorthand for "foldl".
It seems to me like reduce
generally can work without an initial value, whereas fold
always requires it.
I would expect a JavaScript library to throw an exception if it was asked to do something invalid like that, but I suppose it's possible to expect null
or perhaps something else entirely, and can understand requiring the library user to define it themselves if they want it.
from ramda.
I would expect a JavaScript library to throw an exception if it was asked to do something invalid like that,
exactly--and since it is so easy to wind up in a situation where you pass an empty array to foldl1
inadvertently and then the app goes boom. or worse, you wrap it in a try-catch.
Returning undefined
or null
is not good either. The point is to compose these functions; which means we want functions that have--as much as possible in a JS environment--clearly defined inputs and outputs. If foldl1
is in some composition of functions that winds up passing an empty list, and it returns null
, then the consuming function goes boom, or has to type-check its arguments.
That's why I think foldl1
is a non-starter in this environment.
from ramda.
we covered this before: https://github.com/CrossEye/ramda/issues/20
at that time we opted to remove foldl1
and foldr1
--somehow they snuck back in. I've pulled them from the lib. Thanks for the input.
from ramda.
For further reference, there is a great list of how various languages handle this in Wikipedia's Fold Entry
There are a few that do it as Brian is suggesting, including some important ones like Scheme and Scala. There is really only Haskell that uses the foldl/foldl1 distinction. But the overwhelming majority use some sort of overloading to reuse the same name for the two scenarios.
We can't really do that in Ramda with our focus on curried functions. There's no good way to combine those notions with optional parameters, and that's the only version of overloading available in Javascript.
from ramda.
Related Issues (20)
- `equals` returns false if the ordering is different HOT 1
- `reduce` with partial application caches results? HOT 1
- Ramda `0.28.0` contains CWE-843 and CWE-915 HOT 1
- assocPath number path with undefined value expect array but got object HOT 1
- clone new Array(number); HOT 4
- v0.29.0 released HOT 19
- Documentation errors in R.swap examples HOT 2
- 0.29.0 Upgrade Guide HOT 14
- Example with R.find() does not work HOT 3
- `is` implementation can not pass leetcode testing HOT 7
- pathEq types are not consistent with the code in 0.29.0 HOT 5
- Cannot update a nested map via R.modifyPath HOT 2
- R.find and R.propEq HOT 2
- Version exported subfolders HOT 2
- Compose type definitions
- propEq documentation error HOT 4
- [Bug] groupBy result keys order when 0 as first character HOT 6
- R.pipe(R.tryCatch, ...) anomaly HOT 12
- clone does not clone error instance HOT 2
- swap does not work as intended
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ramda.