Sass in the Real World: book 2 of 4

List functions

Function defintion Function description
length($list) This function return the count of the items in a list.
Example:
length((1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); //10
length((R "red") (G "green") (B "blue") (a "alpha")); //4
nth($list, $n) This function extracts the item in the list that is located at the given index value of $n. An error is thrown if the $n value is out of bounds of the length of the list.
Example:
nth((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 6); //6
nth((R "red") (G "green") (B "blue") (a "alpha"), 2); //("G" "green")
join($list1, $list2, [$separator]) This function will join two lists together. If the $seperator value is not provided and the first list is comma seperated and the second one is space seperated, the resulting list will be based on the first list, comma seperated. The values for the $seperator can be comma, space, or auto (which will implemented as described above).
Example:
join((1,2,3,4,5), (6 7 8 9 10)); //(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
join(0.625em, 0.75em, space); //(0.625em 0.75em)
append($list1, $val, [$separator]) This function will allow the addition of a value to the end of a list. The rules for the $seperator follows the description mentioned in the join function.
Example:
append((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 11); //(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
append((0.625em 0.75em), 0.825em, space); //(0.625em 0.75em 0.825em)
zip($lists…) This function will take mutliple lists and create a single multidimensional list with them. It is recommended that when using this function, the lists have the same length otherwise the resulting list will have the length of the smallest list.
Example:
zip("red" "green" "blue", 178 18 204, 90% 50% 75%); //(("red" 178 90%), ("green" 18 50%), ("blue" 204 75%))
index($list, $value) This function will return the index value of the give $value within the $list. If the value is not found, it will return null.
Example:
index((0.625em 0.75em 0.825em), 0.75em); //2
index((0.625em 0.75em 0.825em), 1em); //null
list-separator($list) This function will return the seperator of the list. This value can be either space or comma. If the length of the list is less than 2 then the value returned is space.
Example:
list-separator((0.625em 0.75em 0.825em)); //space
list-separator((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 11); //comma