SassValue

Swift
public class SassValue: Hashable, Sequence, CustomStringConvertible, @unchecked
    Sendable

Common behavior between values passed to or returned from Sass functions.

All Sass values can be treated as lists: singleton values like strings behave like 1-element lists and maps behave like lists of two-element (key, value) lists. Use the SequenceSequence conformance to access the list contents.

SassValue is abstract, you cannot create instances. Instead create instances of subtypes like SassColor.

All the SassValue types have value semantics and are almost all entirely immutable: the only mutability is to do with caching of derived properties.


Topics

Sass properties

var isNull: Bool

Does this value represent Sass’s null value?

Declaration
Swift
public var isNull: Bool { get }

var isTruthy: Bool

Sass considers all values except null and false to be “truthy”, meaning your function should almost always be checking this property instead of trying to downcast to SassBool.

Declaration
Swift
public var isTruthy: Bool { get }

Downcasts

func asString() -> SassString

Reinterpret the value as a string.

Declaration
Swift
public func asString() throws -> SassString
Throws

SassFunctionError.wrongType(...) if it isn’t a string.

func asNumber() -> SassNumber

Reinterpret the value as a number.

Declaration
Swift
public func asNumber() throws -> SassNumber
Throws

SassFunctionError.wrongType(...) if it isn’t a number.

func asColor() -> SassColor

Reinterpret the value as a color.

Declaration
Swift
public func asColor() throws -> SassColor
Throws

SassFunctionError.wrongType(...) if it isn’t a color.

func asBool() -> SassBool

Reinterpret the value as a boolean. But see isTruthy: you almost always don’t want to be using this.

Declaration
Swift
public func asBool() throws -> SassBool
Throws

SassFunctionError.wrongType(...) if it isn’t a boolean.

func asMap() -> SassMap

Reinterpret the value as a map. Empty lists are reinterpreted as the empty map.

Declaration
Swift
public func asMap() throws -> SassMap
Throws

SassFunctionError.wrongType(...) if it isn’t a map or empty list.

func asArgumentList() -> SassArgumentList

Reinterpret the value as an argument list.

Declaration
Swift
public func asArgumentList() throws -> SassArgumentList
Throws

SassFunctionError.wrongType(...) if it isn’t an argument list.

func asCompilerFunction() -> SassCompilerFunction

Reinterpret the value as a compiler function.

Declaration
Swift
public func asCompilerFunction() throws -> SassCompilerFunction
Throws

SassFunctionError.wrongType(...) if it isn’t a compiler function.

func asDynamicFunction() -> SassDynamicFunction

Reinterpret the value as a dynamic function.

Declaration
Swift
public func asDynamicFunction() throws -> SassDynamicFunction
Throws

SassFunctionError.wrongType(...) if it isn’t a compiler function.

func asCalculation() -> SassCalculation

Reinterpret the value as a calculation.

Declaration
Swift
public func asCalculation() throws -> SassCalculation
Throws

SassFunctionError.wrongType(...) if it isn’t a calculation.

Sass listiness

var listCount: Int

The number of values in this value viewed as a list.

Declaration
Swift
public var listCount: Int { get }

func arrayIndexFrom(sassIndex: SassValue) -> Int

Convert a Sass list index.

Declaration
Swift
public func arrayIndexFrom(sassIndex: SassValue) throws -> Int
Parameters
index

A Sass value intended to be used as an index into this value viewed as a list. This must be an integer between 1 and the number of elements inclusive, or negative in the same range to index from the end.

Throws

SassFunctionError if sassIndex is not an integer or out of range.

Return Value

An integer suitable for subscripting the array created from this value, guaranteed to be a valid subscript in the range [0..<count]

func valueAt(sassIndex: SassValue) -> SassValue

Subscript the value using a Sass list index.

(Swift can’t throw exceptions from subscript).

Declaration
Swift
public func valueAt(sassIndex: SassValue) throws -> SassValue
Parameters
sassIndex

A Sass value intended to be used as an index into this value viewed as a list. This must be an integer between 1 and the number of elements inclusive, or a negative number with similar magnitude to index back from the end.

Throws

SassFunctionError if sassIndex is not an integer or out of range.

Return Value

The value at the Sass index.

var hasBrackets: Bool

Is this value, viewed as a list, surrounded by brackets?

Declaration
Swift
public var hasBrackets: Bool { get }

var separator: SassList.Separator

The list separator used by this value when viewed as a list.

Declaration
Swift
public var separator: SassList.Separator { get }

Misc

static func ==(lhs: SassValue, rhs: SassValue) -> Bool

Two SassValues are generally equal if they have the same dynamic type and compare equally as that type. In addition, empty lists and maps compare as equal.

Declaration
Swift
public static func == (lhs: SassValue, rhs: SassValue) -> Bool

func accept<V, R>(visitor: V) -> R

Call the corresponding method of visitor against this object.

Declaration
Swift
public func accept<V, R>(visitor: V) throws -> R
where V: SassValueVisitor, R == V.ReturnType

func hash(into: inout Hasher)

SassValue can be used as a dictionary key.

Declaration
Swift
public func hash(into hasher: inout Hasher)

func makeIterator() -> AnyIterator<SassValue>

An iterator for the values in the list, for SequenceSequence conformance.

Declaration
Swift
public func makeIterator() -> AnyIterator<SassValue>

var description: String

A short description of the value.

Declaration
Swift
public var description: String { get }

Other Definitions

func asMixin() -> SassMixin

Reinterpret the value as a mixin.

Declaration
Swift
public func asMixin() throws -> SassMixin
Throws

SassFunctionError.wrongType(...) if it isn’t a mixin.