ListFunctions 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/lib/ListFunctions.rb +29 -29
  2. data/stylesheets/ListFunctions/_chunk.scss +32 -32
  3. data/stylesheets/ListFunctions/_count-values.scss +32 -32
  4. data/stylesheets/ListFunctions/_debug.scss +34 -34
  5. data/stylesheets/ListFunctions/_first.scss +12 -12
  6. data/stylesheets/ListFunctions/_insert-nth.scss +51 -51
  7. data/stylesheets/ListFunctions/_is-symmetrical.scss +22 -22
  8. data/stylesheets/ListFunctions/_last-index.scss +24 -24
  9. data/stylesheets/ListFunctions/_last.scss +12 -12
  10. data/stylesheets/ListFunctions/_loop.scss +20 -20
  11. data/stylesheets/ListFunctions/_prepend.scss +15 -15
  12. data/stylesheets/ListFunctions/_purge.scss +20 -20
  13. data/stylesheets/ListFunctions/_remove-duplicates.scss +29 -29
  14. data/stylesheets/ListFunctions/_remove-nth.scss +22 -22
  15. data/stylesheets/ListFunctions/_remove.scss +18 -18
  16. data/stylesheets/ListFunctions/_replace-nth.scss +49 -49
  17. data/stylesheets/ListFunctions/_replace.scss +31 -31
  18. data/stylesheets/ListFunctions/_reverse.scss +29 -29
  19. data/stylesheets/ListFunctions/_slice.scss +59 -59
  20. data/stylesheets/ListFunctions/_sort.scss +42 -0
  21. data/stylesheets/ListFunctions/_sum.scss +32 -32
  22. data/stylesheets/ListFunctions/_to-string.scss +28 -28
  23. data/stylesheets/_ListFunctions.scss +94 -90
  24. data/templates/project/sass/ListFunctions/_chunk.scss +32 -32
  25. data/templates/project/sass/ListFunctions/_count-values.scss +32 -32
  26. data/templates/project/sass/ListFunctions/_debug.scss +34 -34
  27. data/templates/project/sass/ListFunctions/_first.scss +12 -12
  28. data/templates/project/sass/ListFunctions/_insert-nth.scss +51 -51
  29. data/templates/project/sass/ListFunctions/_is-symmetrical.scss +22 -22
  30. data/templates/project/sass/ListFunctions/_last-index.scss +24 -24
  31. data/templates/project/sass/ListFunctions/_last.scss +12 -12
  32. data/templates/project/sass/ListFunctions/_loop.scss +20 -20
  33. data/templates/project/sass/ListFunctions/_prepend.scss +15 -15
  34. data/templates/project/sass/ListFunctions/_purge.scss +20 -20
  35. data/templates/project/sass/ListFunctions/_remove-duplicates.scss +29 -29
  36. data/templates/project/sass/ListFunctions/_remove-nth.scss +22 -22
  37. data/templates/project/sass/ListFunctions/_remove.scss +18 -18
  38. data/templates/project/sass/ListFunctions/_replace-nth.scss +49 -49
  39. data/templates/project/sass/ListFunctions/_replace.scss +31 -31
  40. data/templates/project/sass/ListFunctions/_reverse.scss +29 -29
  41. data/templates/project/sass/ListFunctions/_slice.scss +59 -59
  42. data/templates/project/sass/ListFunctions/_sum.scss +32 -32
  43. data/templates/project/sass/ListFunctions/_to-string.scss +28 -28
  44. data/templates/project/sass/_ListFunctions.scss +90 -90
  45. metadata +18 -11
  46. checksums.yaml +0 -7
@@ -1,32 +1,32 @@
1
- /**
2
- * Chunk $list into $size large lists
3
- * -------------------------------------------------------------------------------
4
- * @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
5
- * @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
6
- * @example chunk( a, 3 ) => a
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $size [Number] : length of lists
10
- * -------------------------------------------------------------------------------
11
- * @return [List]
12
- */
13
- @function chunk($list, $size) {
14
- $n: ceil(length($list) / $size);
15
- $temp-index: 0;
16
- $result: ();
17
-
18
- @for $i from 1 through $n {
19
- $temp-list: ();
20
-
21
- @for $j from 1 + $temp-index through $size + $temp-index {
22
- @if $j <= length($list) {
23
- $temp-list: append($temp-list, nth($list, $j));
24
- }
25
- }
26
-
27
- $result: append($result, $temp-list);
28
- $temp-index: $temp-index + $size;
29
- }
30
-
31
- @return $result;
32
- }
1
+ /**
2
+ * Chunk $list into $size large lists
3
+ * -------------------------------------------------------------------------------
4
+ * @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
5
+ * @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
6
+ * @example chunk( a, 3 ) => a
7
+ * -------------------------------------------------------------------------------
8
+ * @param $list [List] : list
9
+ * @param $size [Number] : length of lists
10
+ * -------------------------------------------------------------------------------
11
+ * @return [List]
12
+ */
13
+ @function chunk($list, $size) {
14
+ $n: ceil(length($list) / $size);
15
+ $temp-index: 0;
16
+ $result: ();
17
+
18
+ @for $i from 1 through $n {
19
+ $temp-list: ();
20
+
21
+ @for $j from 1 + $temp-index through $size + $temp-index {
22
+ @if $j <= length($list) {
23
+ $temp-list: append($temp-list, nth($list, $j));
24
+ }
25
+ }
26
+
27
+ $result: append($result, $temp-list);
28
+ $temp-index: $temp-index + $size;
29
+ }
30
+
31
+ @return $result;
32
+ }
@@ -1,33 +1,33 @@
1
- /**
2
- * Count the number of occurrences of each value of $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `replace-nth()`
5
- * -------------------------------------------------------------------------------
6
- * @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
7
- * @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
8
- * @example count-values( a ) => a 1
9
- * -------------------------------------------------------------------------------
10
- * @param $list [List] : list
11
- * -------------------------------------------------------------------------------
12
- * @return [List]
13
- */
14
- @function count-values($list) {
15
- $keys : ();
16
- $counts : ();
17
-
18
- @each $item in $list {
19
- $index: index($keys, $item);
20
-
21
- @if not $index {
22
- $keys : append($keys, $item);
23
- $counts : append($counts, 1);
24
- }
25
-
26
- @else {
27
- $count : nth($counts, $index) + 1;
28
- $counts : replace-nth($counts, $index, $count);
29
- }
30
- }
31
-
32
- @return zip($keys, $counts);
1
+ /**
2
+ * Count the number of occurrences of each value of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `replace-nth()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
7
+ * @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
8
+ * @example count-values( a ) => a 1
9
+ * -------------------------------------------------------------------------------
10
+ * @param $list [List] : list
11
+ * -------------------------------------------------------------------------------
12
+ * @return [List]
13
+ */
14
+ @function count-values($list) {
15
+ $keys : ();
16
+ $counts : ();
17
+
18
+ @each $item in $list {
19
+ $index: index($keys, $item);
20
+
21
+ @if not $index {
22
+ $keys : append($keys, $item);
23
+ $counts : append($counts, 1);
24
+ }
25
+
26
+ @else {
27
+ $count : nth($counts, $index) + 1;
28
+ $counts : replace-nth($counts, $index, $count);
29
+ }
30
+ }
31
+
32
+ @return zip($keys, $counts);
33
33
  }
@@ -1,34 +1,34 @@
1
- /**
2
- * Returns $list as a string
3
- * -------------------------------------------------------------------------------
4
- * @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
5
- * @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
6
- * @example debug( a ) => [ a ]
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * -------------------------------------------------------------------------------
10
- * @return [String]
11
- */
12
- @function debug($list) {
13
- $result: #{"[ "};
14
-
15
- @each $item in $list {
16
-
17
- @if length($item) > 1 {
18
- $result: $result#{debug($item)};
19
- }
20
-
21
- @else {
22
- $result: $result#{$item};
23
- }
24
-
25
- @if index($list, $item) != length($list) {
26
- $result: $result#{", "};
27
- }
28
-
29
- }
30
-
31
- $result: $result#{" ]"};
32
-
33
- @return $result;
34
- }
1
+ /**
2
+ * Returns $list as a string
3
+ * -------------------------------------------------------------------------------
4
+ * @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
5
+ * @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
6
+ * @example debug( a ) => [ a ]
7
+ * -------------------------------------------------------------------------------
8
+ * @param $list [List] : list
9
+ * -------------------------------------------------------------------------------
10
+ * @return [String]
11
+ */
12
+ @function debug($list) {
13
+ $result: #{"[ "};
14
+
15
+ @each $item in $list {
16
+
17
+ @if length($item) > 1 {
18
+ $result: $result#{debug($item)};
19
+ }
20
+
21
+ @else {
22
+ $result: $result#{$item};
23
+ }
24
+
25
+ @if index($list, $item) != length($list) {
26
+ $result: $result#{", "};
27
+ }
28
+
29
+ }
30
+
31
+ $result: $result#{" ]"};
32
+
33
+ @return $result;
34
+ }
@@ -1,13 +1,13 @@
1
- /**
2
- * Returns first element of $list
3
- * -------------------------------------------------------------------------------
4
- * @example first( (a, b, c) ) => a
5
- * @example first( a ) => a
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * -------------------------------------------------------------------------------
9
- * @return [Literal]
10
- */
11
- @function first($list) {
12
- @return nth($list, 1);
1
+ /**
2
+ * Returns first element of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example first( (a, b, c) ) => a
5
+ * @example first( a ) => a
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * -------------------------------------------------------------------------------
9
+ * @return [Literal]
10
+ */
11
+ @function first($list) {
12
+ @return nth($list, 1);
13
13
  }
@@ -1,52 +1,52 @@
1
- /**
2
- * Add $value at $index in $list
3
- * -------------------------------------------------------------------------------
4
- * @dependence `purge()`
5
- * -------------------------------------------------------------------------------
6
- * @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
7
- * @example insert-nth( (a, b, c), 0, z ) => error
8
- * @example insert-nth( (a, b, c), -1, z ) => error
9
- * @example insert-nth( (a, b, c), 10, z ) => error
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $index [Number] : index to add
13
- * @param $value [Literal] : value to add
14
- * -------------------------------------------------------------------------------
15
- * @raise [Error] if $index isn't an integer
16
- * @raise [Error] if $index is strictly lesser than 1
17
- * @raise [Error] if $index is strictly greater than length of $list
18
- * -------------------------------------------------------------------------------
19
- * @return [List] | false
20
- */
21
- @function insert-nth($list, $index, $value) {
22
- $result: false;
23
-
24
- @if type-of($index) != number {
25
- @warn "$index: #{quote($index)} is not a number for `insert-nth`.";
26
- @return $result;
27
- }
28
-
29
- @else if $index < 1 {
30
- @warn "List index 0 must be a non-zero integer for `insert-nth`";
31
- @return $result;
32
- }
33
-
34
- @else if $index > length($list) {
35
- @warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
36
- @return $result;
37
- }
38
-
39
- @else {
40
- $result: ();
41
-
42
- @for $i from 1 through length($list) {
43
- @if $i == $index {
44
- $result: append($result, $value);
45
- }
46
-
47
- $result: append($result, nth($list, $i));
48
- }
49
- }
50
-
51
- @return purge($result);
1
+ /**
2
+ * Add $value at $index in $list
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `purge()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
7
+ * @example insert-nth( (a, b, c), 0, z ) => error
8
+ * @example insert-nth( (a, b, c), -1, z ) => error
9
+ * @example insert-nth( (a, b, c), 10, z ) => error
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * @param $index [Number] : index to add
13
+ * @param $value [Literal] : value to add
14
+ * -------------------------------------------------------------------------------
15
+ * @raise [Error] if $index isn't an integer
16
+ * @raise [Error] if $index is strictly lesser than 1
17
+ * @raise [Error] if $index is strictly greater than length of $list
18
+ * -------------------------------------------------------------------------------
19
+ * @return [List] | false
20
+ */
21
+ @function insert-nth($list, $index, $value) {
22
+ $result: false;
23
+
24
+ @if type-of($index) != number {
25
+ @warn "$index: #{quote($index)} is not a number for `insert-nth`.";
26
+ @return $result;
27
+ }
28
+
29
+ @else if $index < 1 {
30
+ @warn "List index 0 must be a non-zero integer for `insert-nth`";
31
+ @return $result;
32
+ }
33
+
34
+ @else if $index > length($list) {
35
+ @warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
36
+ @return $result;
37
+ }
38
+
39
+ @else {
40
+ $result: ();
41
+
42
+ @for $i from 1 through length($list) {
43
+ @if $i == $index {
44
+ $result: append($result, $value);
45
+ }
46
+
47
+ $result: append($result, nth($list, $i));
48
+ }
49
+ }
50
+
51
+ @return purge($result);
52
52
  }
@@ -1,23 +1,23 @@
1
- /**
2
- * Test if $list is symmetrical (one-level deep)
3
- * -------------------------------------------------------------------------------
4
- * @dependence `reverse()`
5
- * -------------------------------------------------------------------------------
6
- * @example is-symmetrical( (a, b, c, d, e) ) => false
7
- * @example is-symmetrical( (a, b, c, b, a) ) => true
8
- * @example is-symmetrical( a ) => true
9
- * @example is-symmetrical( a, b c d, a ) => true
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * -------------------------------------------------------------------------------
13
- * @return [Boolean]
14
- */
15
- @function is-symmetrical($list) {
16
- $result: ();
17
-
18
- @each $item in $list {
19
- $result: append($result, $item, space);
20
- }
21
-
22
- @return $result == reverse($result);
1
+ /**
2
+ * Test if $list is symmetrical (one-level deep)
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `reverse()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example is-symmetrical( (a, b, c, d, e) ) => false
7
+ * @example is-symmetrical( (a, b, c, b, a) ) => true
8
+ * @example is-symmetrical( a ) => true
9
+ * @example is-symmetrical( a, b c d, a ) => true
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * -------------------------------------------------------------------------------
13
+ * @return [Boolean]
14
+ */
15
+ @function is-symmetrical($list) {
16
+ $result: ();
17
+
18
+ @each $item in $list {
19
+ $result: append($result, $item, space);
20
+ }
21
+
22
+ @return $result == reverse($result);
23
23
  }
@@ -1,24 +1,24 @@
1
- /**
2
- * Returns last index of $value in $list
3
- * -------------------------------------------------------------------------------
4
- * @example last-index( (a, b, c, a), a ) => 4
5
- * @example last-index( (a, b, c), z ) => null
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * @param $value [Literal] : value to be searched for
9
- * -------------------------------------------------------------------------------
10
- * @return [Number] | null
11
- */
12
- @function last-index($list, $value) {
13
-
14
- @for $i from length($list) * -1 through -1 {
15
- $i: abs($i);
16
-
17
- @if nth($list, $i) == $value {
18
- @return $i;
19
- }
20
-
21
- }
22
-
23
- @return null;
24
- }
1
+ /**
2
+ * Returns last index of $value in $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example last-index( (a, b, c, a), a ) => 4
5
+ * @example last-index( (a, b, c), z ) => null
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * @param $value [Literal] : value to be searched for
9
+ * -------------------------------------------------------------------------------
10
+ * @return [Number] | null
11
+ */
12
+ @function last-index($list, $value) {
13
+
14
+ @for $i from length($list) * -1 through -1 {
15
+ $i: abs($i);
16
+
17
+ @if nth($list, $i) == $value {
18
+ @return $i;
19
+ }
20
+
21
+ }
22
+
23
+ @return null;
24
+ }
@@ -1,13 +1,13 @@
1
- /**
2
- * Returns last element of $list
3
- * -------------------------------------------------------------------------------
4
- * @example last( (a, b, c) ) => c
5
- * @example last( a ) => a
6
- * -------------------------------------------------------------------------------
7
- * @param $list [List] : list
8
- * -------------------------------------------------------------------------------
9
- * @return [Literal]
10
- */
11
- @function last($list) {
12
- @return nth($list, length($list));
1
+ /**
2
+ * Returns last element of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example last( (a, b, c) ) => c
5
+ * @example last( a ) => a
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * -------------------------------------------------------------------------------
9
+ * @return [Literal]
10
+ */
11
+ @function last($list) {
12
+ @return nth($list, length($list));
13
13
  }