LeafKit Documentation

Structure Leaf​Data

public struct LeafData: CustomStringConvertible,
                        Equatable,
                        ExpressibleByDictionaryLiteral,
                        ExpressibleByStringLiteral,
                        ExpressibleByIntegerLiteral,
                        ExpressibleByBooleanLiteral,
                        ExpressibleByArrayLiteral,
                        ExpressibleByFloatLiteral,
                        ExpressibleByNilLiteral  

LeafData is a "pseudo-protocol" wrapping the physically storable Swift data types Leaf can use directly

  • (Bool, Int, Double, String, Array, Dictionary, Data) are the inherent root types supported, all of which may also be representable as Optional values.

  • NaturalType presents these cases plus Void as a case for functional LeafSymbols

  • nil is creatable, but only within context of a root base type - eg, .nil(.bool) == Bool?

%19 LeafData LeafData CustomStringConvertible CustomStringConvertible LeafData->CustomStringConvertible ExpressibleByBooleanLiteral ExpressibleByBooleanLiteral LeafData->ExpressibleByBooleanLiteral ExpressibleByArrayLiteral ExpressibleByArrayLiteral LeafData->ExpressibleByArrayLiteral ExpressibleByStringLiteral ExpressibleByStringLiteral LeafData->ExpressibleByStringLiteral ExpressibleByFloatLiteral ExpressibleByFloatLiteral LeafData->ExpressibleByFloatLiteral ExpressibleByIntegerLiteral ExpressibleByIntegerLiteral LeafData->ExpressibleByIntegerLiteral ExpressibleByNilLiteral ExpressibleByNilLiteral LeafData->ExpressibleByNilLiteral Equatable Equatable LeafData->Equatable ExpressibleByDictionaryLiteral ExpressibleByDictionaryLiteral LeafData->ExpressibleByDictionaryLiteral

Nested Types

LeafData.NaturalType

The concrete instantiable object types for a LeafData

Conforms To

CustomStringConvertible
Equatable
ExpressibleByArrayLiteral
ExpressibleByBooleanLiteral
ExpressibleByDictionaryLiteral
ExpressibleByFloatLiteral
ExpressibleByIntegerLiteral
ExpressibleByNilLiteral
ExpressibleByStringLiteral

Initializers

init(_:​)

public init(_ leafData: LeafDataRepresentable)  

init(nil​Literal:​)

public init(nilLiteral: ())  

init(string​Literal:​)

public init(stringLiteral value: StringLiteralType)  

init(integer​Literal:​)

public init(integerLiteral value: IntegerLiteralType)  

init(float​Literal:​)

public init(floatLiteral value: FloatLiteralType)  

init(boolean​Literal:​)

public init(booleanLiteral value: BooleanLiteralType)  

init(array​Literal:​)

public init(arrayLiteral elements: LeafData...)  

init(dictionary​Literal:​)

public init(dictionaryLiteral elements: (String, LeafData)...)  

Properties

celf

public var celf: NaturalType  

The case-self identity

is​Nil

public var isNil: Bool  

Returns true if the data is nil or void.

is​Collection

public var isCollection: Bool  

Returns true if the data can hold other data - we don't consider Optional for this purpose

description

public var description: String  

short

public var short: String  

has​Uniform​Type

public var hasUniformType: Bool?  

Returns true if the object has a single uniform type

  • Always true for invariant non-containers

  • True or false for containers if determinable

  • Nil if the object is variant lazy data, or invariant lazy producing a container, or a container holding such

uniform​Type

public var uniformType: NaturalType?  

Returns the uniform type of the object, or nil if it can't be determined/is a non-uniform container

bool

public var bool: Bool?  

Attempts to convert to Bool or returns nil.

string

public var string: String?  

Attempts to convert to String or returns nil.

int

public var int: Int?  

Attempts to convert to Int or returns nil.

double

public var double: Double?  

Attempts to convert to Double or returns nil.

data

public var data: Data?  

Attempts to convert to Data or returns nil.

dictionary

public var dictionary: [String: LeafData]?  

Attempts to convert to [String: LeafData] or returns nil.

array

public var array: [LeafData]?  

Attempts to convert to [LeafData] or returns nil.

true​Nil

public static var trueNil: LeafData  

For convenience, trueNil is stored as .optional(nil, .void)

Methods

is​Castable(to:​)

public func isCastable(to type: LeafData.NaturalType) -> Bool  

Returns true if concrete object can be exactly or losslessly cast to a second type

  • EG: .nil -> .string(""), .int(1) -> .double(1.0), .bool(true) -> .string("true") are all one-way lossless conversions

  • This does not imply it's not possible to coerce data - handle with coerce(to:) EG: .string("") -> .nil, .string("1") -> .bool(true)

is​Coercible(to:​)

public func isCoercible(to type: LeafData.NaturalType) -> Bool  

Returns true if concrete object is potentially directly coercible to a second type in some way

  • EG: .array() -> .dictionary() where array indices become keys or .int(1) -> .bool(true)

  • This does not validate the data itself in coercion

bool(_:​)

public static func bool(_ value: Bool?) -> LeafData  

Creates a new LeafData from a Bool.

string(_:​)

public static func string(_ value: String?) -> LeafData  

Creates a new LeafData from a String.

int(_:​)

public static func int(_ value: Int?) -> LeafData  

Creates a new LeafData from am Int.

double(_:​)

public static func double(_ value: Double?) -> LeafData  

Creates a new LeafData from a Double.

data(_:​)

public static func data(_ value: Data?) -> LeafData  

Creates a new LeafData from Data.

dictionary(_:​)

public static func dictionary(_ value: [String: LeafData]?) -> LeafData  

Creates a new LeafData from [String: LeafData].

array(_:​)

public static func array(_ value: [LeafData]?) -> LeafData  

Creates a new LeafData from [LeafData].

`nil`(_:​)

public static func `nil`(_ type: LeafData.NaturalType) -> LeafData  

Creates a new LeafData for Optional<LeafData>

cast(to:​)

public func cast(to: LeafData.NaturalType) -> LeafData  

coerce(to:​)

public func coerce(to: LeafData.NaturalType) -> LeafData  

Operators

==

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