question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use Array (Pair a b) in unfold

See original GitHub issue

Quoting @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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
CrossEyecommented, Apr 20, 2017

After weeks away, I’m back. And this is fascinating. I finally understand the original posts on this. And I really like updating unfold.

1reaction
davidchamberscommented, Mar 22, 2017

What if the user returns ['oops'] ?

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 suggest maybePair instead.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found