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.

Suggestion: partition functions

See original GitHub issue

Examples

partition

Takes a function and an iterable, returns a pair of 2 iterables.

// usage
const [evens, odds] = partition(
  n => n  % 2 === 0, // func: (x: T) => boolean
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] // iterable: Iterable<T>
)

// result
expect(Array.from(evens)).toEqual([0, 2, 4, 6, 8])
expect(Array.from(odds)).toEqual([1, 3, 5, 7, 9])

multiPartition

Takes a function and an iterable, returns an array of iterables.

// usage
const [a, b, c] = multiPartition(
  x => x % 3, // func: (x: T) => number
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] // iterable: Iterable<T>
)

// result
expect(Array.from(a)).toEqual([0, 3, 6, 9])
expect(Array.from(b)).toEqual([1, 4, 7])
expect(Array.from(c)).toEqual([2, 5, 8])

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:53 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sithmelcommented, Feb 14, 2019

Given that we see a valid use case consuming iterables one by one. I am going to adjust the code accordingly and publish a PR (I am probably going to steal your unit tests @KSXGitHub )

1reaction
KSXGitHubcommented, Jan 17, 2019

@sithmel I’ll wait. But I think you should make a pull request so we may discuss.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I. Improved partition functions and thermodynamic quantities ...
New partition functions for equilibrium, normal, and ortho and para hydrogen are calculated and thermodynamic quantities are reported for the temperature ...
Read more >
Approximating Partition Functions - Windows On Theory
Another method of calculating the partition function involves Taylor expanding its logarithm around a cleverly selected point. This approach was ...
Read more >
Quantum Statistics 37 : Partition Function and Free Energy
In this video I continue with my series of tutorial videos on Quantum Statistics. This is intended to be part of both my...
Read more >
Partition Functions with spin in AdS_2 via Quasinormal Mode ...
Abstract: We extend the results of arXiv:1401.7016, computing one loop partition functions for massive fields with spin half in AdS_2 using ...
Read more >
On the Uncomputability of Partition Functions in Energy-Based ...
In this paper, we argue that energy-based sequence models backed by expressive parametric families can result in uncomputable and inapproximable partition ...
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