-
Notifications
You must be signed in to change notification settings - Fork 0
/
_inner-join.scss
57 lines (52 loc) · 1.53 KB
/
_inner-join.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@import 'inc';
@import 'filter';
// as gross as this is there is no way that I know of to get around it. :(
$_sass-fire-inner-join-fn: '';
$_sass-fire-inner-join-list: '';
/// Takes a predicate and two lists and returns a list comprising each of
/// the elements of `a` which is equal to one or more
/// elements of `b` according to `pred`.
///
/// @group relation
/// @param {Function} pred
/// @param {Array} a
/// @param {Array} b
/// @return {Array}
/// @see intersection
///
/// @example scss - inner-join
///
/// $buffalos: inner-join(
/// (record, id) => record.id === id,
/// [{id: 824, name: 'Richie Furay'},
/// {id: 956, name: 'Dewey Martin'},
/// {id: 313, name: 'Bruce Palmer'},
/// {id: 456, name: 'Stephen Stills'},
/// {id: 177, name: 'Neil Young'}],
/// [177, 456, 999]
/// );
/// @debug $buffalos; //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
///
@function inner-join($pred, $a, $b) {
$_sass-fire-inner-join-fn: $pred !global;
$_sass-fire-inner-join-list: $b !global;
@return filter(_inner-join-filter, $a);
}
@function _inner-join-filter($x) {
@return _includes-with(
$_sass-fire-inner-join-fn,
$x,
$_sass-fire-inner-join-list
);
}
@function _includes-with($pred, $x, $list) {
$idx: 1;
$length: length($list);
@while $idx <= $length {
@if (call(get-function($pred), $x, nth($list, $idx))) {
@return true;
}
$idx: inc($idx);
}
@return false;
}