-
Notifications
You must be signed in to change notification settings - Fork 0
Working with Map, Set, iterables
Conan edited this page Oct 4, 2022
·
1 revision
import { sift } from 'sift-r'
import { sift } from 'sift-r'
import { lt } from 'match-iz'
const [oneYearOlds, lessThan40, theRest] = sift(
new Set([
{ user: 'barney', age: 36, active: false },
{ user: 'fred', age: 40, active: true },
{ user: 'pebbles', age: 1, active: false }
]),
{ age: 1, active: false },
{ age: lt(40) }
)
// oneYearOlds ===
// new Set([
// { user: 'pebbles', age: 1, active: false }
// ])
// lessThan40 ===
// new Set([
// { user: 'barney', age: 36, active: false }
// ])
// theRest ===
// new Set([
// { user: 'fred', age: 40, active: true }
// ])
import { sift } from 'sift-r'
import { lt } from 'match-iz'
const [oneYearOlds, lessThan40, theRest] = sift(
new Map([
[0, { user: 'barney', age: 36, active: false }],
[1, { user: 'fred', age: 40, active: true }],
[2, { user: 'pebbles', age: 1, active: false }]
]),
{ age: 1, active: false },
{ age: lt(40) }
)
// oneYearOlds ===
// new Map([
// [2, { user: 'pebbles', age: 1, active: false }]
// ])
// lessThan40 ===
// new Map([
// [0, { user: 'barney', age: 36, active: false }]
// ])
// theRest ===
// new Map([
// [1, { user: 'fred', age: 40, active: true }]
// ])
import { sift } from 'sift-r'
import { lt } from 'match-iz'
function* flintstones() {
yield { user: 'barney', age: 36, active: false }
yield { user: 'fred', age: 40, active: true }
yield { user: 'pebbles', age: 1, active: false }
}
const [oneYearOlds, lessThan40, theRest] = sift(
flintstones(),
{ age: 1, active: false },
{ age: lt(40) }
)
// oneYearOlds ===
// [{ user: 'pebbles', age: 1, active: false }]
// lessThan40 ===
// [{ user: 'barney', age: 36, active: false }]
// theRest ===
// [{ user: 'fred', age: 40, active: true }]
sift-r
📥 | on npm | docs home | top of page