<commit_before># @most/sample

Create a new stream by combining sampled values from many input streams.

## Install

`npm install @most/sample`

## API

#### sample :: (a → b → c) → Stream a → Stream b → Stream c

```
stream:                          -2--3-4--2--5--6---7---1->
sampler:                         ---1----2----3-------5--->
sample(sum, sampler, stream):    ---3----6----8-------12-->
```
`sample` produces a value only when an event arrives on the sampler,
passing the value of the `sampler` along with the latest value from
`stream`.

`sample` is curried by default.

```js
import {periodic, of} from 'most';
import {sample} from '@most/sample';

const add = (x, y) => x + y;

const sampleWithArray = sample(Array);
const sampleEachSecond = sampleWithArray(periodic(1000, 1).scan(add, 0));

sampleEachSecond(of(2))
  .take(3)
  .observe(([sec, val]) => {
    console.log('Seconds Passed: ' + sec);
    console.log(sec * value);
  });
// Seconds Passed: 0
// 0
// Seconds Passed: 1
// 2
// Seconds Passed: 2
// 4

```

#### sampleArray :: (a → b → [c]) → Stream a → Stream b → [Stream c]

```
s1:                             -2--3-4--2--5--6---7---1->
s2:                             -1--2---3----------4----->
sampler:                        ---1----2----3-------5--->
sample(sum, sampler, [s1, s2]): ---4----9----11-------16-->
```
`sampleArray` produces a value only when an event arrives on the sampler,
passing the value of the `sampler` along with an array of latest values from
streams contained in `arrayOfStreams`.

`sampleArray` is curried by default.

```js
import {periodic, of} from 'most';
import {sampleArray} from '@most/sample';

const add = (x, y) => x + y;

const sampleWithArray = sampleArray(Array);
const sampleEachSecond = sampleWithArray(periodic(1000, 1).scan(add, 0));<commit_msg>Tweak sampleArray type signature (#4)<commit_after># @most/sample

Create a new stream by combining sampled values from many input streams.

## Install

`npm install @most/sample`

## API

#### sample :: (a → b → c) → Stream a → Stream b → Stream c

```
stream:                          -2--3-4--2--5--6---7---1->
sampler:                         ---1----2----3-------5--->
sample(sum, sampler, stream):    ---3----6----8-------12-->
```
`sample` produces a value only when an event arrives on the sampler,
passing the value of the `sampler` along with the latest value from
`stream`.

`sample` is curried by default.

```js
import {periodic, of} from 'most';
import {sample} from '@most/sample';

const add = (x, y) => x + y;

const sampleWithArray = sample(Array);
const sampleEachSecond = sampleWithArray(periodic(1000, 1).scan(add, 0));

sampleEachSecond(of(2))
  .take(3)
  .observe(([sec, val]) => {
    console.log('Seconds Passed: ' + sec);
    console.log(sec * value);
  });
// Seconds Passed: 0
// 0
// Seconds Passed: 1
// 2
// Seconds Passed: 2
// 4

```

#### sampleArray :: (a → [b] → c) → Stream a → [Stream b] → Stream c

```
s1:                             -2--3-4--2--5--6---7---1->
s2:                             -1--2---3----------4----->
sampler:                        ---1----2----3-------5--->
sample(sum, sampler, [s1, s2]): ---4----9----11-------16-->
```
`sampleArray` produces a value only when an event arrives on the sampler,
passing the value of the `sampler` along with an array of latest values from
streams contained in `arrayOfStreams`.

`sampleArray` is curried by default.

```js
import {periodic, of} from 'most';
import {sampleArray} from '@most/sample';

const add = (x, y) => x + y;

const sampleWithArray = sampleArray(Array);
const sampleEachSecond = sampleWithArray(periodic(1000, 1).scan(add, 0));
{'fraction_non_alphanumeric': 0.20278384279475983, 'fraction_numerical': 0.034661572052401744, 'mean_word_length': 2.251996450754215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4273674', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1186, 'n_words': 407}