Skip to content

Hashable structured data #82

@hhanesand

Description

@hhanesand

Would it be possible to implement a Hashable extension to StructuredData ?

I see we already provide an implementation for equals, so this would be a nice addition, as it would save me from unwrapping the structured data type.

Here is my idea.

extension StructuredDataWrapper {
    
    var hashValue: Int {
        switch self.wrapped {
            
        case let .bool(bool):
            return bool.hashValue
            
        case let .number(number):
            switch number {
            case let .int(int):
                return int.hashValue
                
            case let .double(double):
                return double.hashValue
                
            case let .uint(uint):
                return uint.hashValue
            }
            
        case let .string(string):
            return string.hashValue
            
        case let .date(date):
            return date.hashValue
            
        case let .bytes(bytes):
            return bytes.makeString().hashValue
            
        case let .array(array):
            // Not too sure here
            return 0
            
        case let .object(object):
            // Not too sure here
            return 0
            
        case .null:
            return 0
        }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions