Use Array (Pair a b) in unfold
See original GitHub issueQuoting @davidchambers:
Since we don’t have the option of using Maybe (Pair a b), we’d need to use Array (Pair a b) and assume that the array’s length will either be zero or one ([] or [[‘foo’, 42]], say).
Perhaps in this form?
module.exports = _curry2(function unfold(fn, seed) {
var pair = fn(seed);
var result = [];
while (pair && pair[0] && pair[0].length === 2) {
result[result.length] = pair[0][0];
pair = fn(pair[0][1]);
}
return result;
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Find all pairs (a, b) in an array such that a % b = k
Given an array with distinct elements, the task is to find the pairs in the array such that a % b = k,...
Read more >Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created....
Read more >Array (FSharp.Core) - F# Core Engineering
Compares two arrays using the given comparison function, ... Tests if any pair of corresponding elements of the arrays satisfies the given predicate....
Read more >c++ - How to have an array of integer pairs sorted by both ...
I have a set of data in forms of pairs of integers like {1,1}{600,2}{10,4} etc. Lets call them {a,b}. I am using an...
Read more >Erlang -- array
fun((Index :: array_indx(), Value :: Type, Acc :: A) -> B). Folds the array elements using the specified function and initial accumulator value....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After weeks away, I’m back. And this is fascinating. I finally understand the original posts on this. And I really like updating
unfold
.We likely fail with an unhelpful type error. That’s the Ramda way. Suppressing the error would be far worse, though.
Also,
pair
is a misleading name. I suggestmaybePair
instead.