Skip to content

Releases: 0xOpenBytes/c

4.0.0

06 Mar 05:12

Choose a tag to compare

What's Changed

New Contributors

  • @haIIux made their first contribution in #9

Full Changelog: 3.0.2...4.0.0

3.0.2

31 Jan 04:09
1c43b44

Choose a tag to compare

Full Changelog: 3.0.1...3.0.2

3.0.1

18 Jan 02:53
e50c296

Choose a tag to compare

What's Changed

Full Changelog: 3.0.0...3.0.1

3.0.0

23 Oct 02:03
f24cc61

Choose a tag to compare

What's Changed

  • Added InvalidTypeError
  • Removed force unwraps for throwing
  • Changed JSON to a struct and removed conformance to Cacheable

Full Changelog: 2.0.0...3.0.0

2.0.0

21 Oct 00:25
6feaaaf

Choose a tag to compare

c

Micro Composition

What is c?

c is a simple composition framework. You have the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved.

Where can c be used?

c can be used anywhere to create transformations or interact with the cache.

Examples

BiDirectionalTransformation of String and Int

let transformer = c.transformer(
    from: { string in Int(string) },
    to: { int in "\(String(describing: int))" }
)

let string = transformer.to(3)
let int = transformer.from("3")

try t.assert(transformer.to(int), isEqualTo: string)

Cache

let cache = c.Cache()

cache.set(value: Double.pi, forKey: "🥧")

let pi: Double = cache.get("🥧") ?? 0

try t.assert(pi, isEqualTo: .pi)

let resolvedValue: Double = try cache.resolve("🥧")

try t.assert(resolvedValue, isEqualTo: .pi)
                    
cache.remove("🥧")

let nilValue: Double? = cache.get("🥧")

try t.assert(isNil: nilValue)

KeyedCache

enum CacheKey: Hashable { ... }

let cache = c.KeyedCache<CacheKey>()

cache.set(value: Double.pi, forKey: CacheKey.piKey)

let pi: Double = cache.get(.piKey) ?? 0

try t.assert(pi, isEqualTo: .pi)

let resolvedValue: Double = try cache.resolve(.piKey)

try t.assert(resolvedValue, isEqualTo: .pi)
                    
cache.remove(.piKey)

let nilValue: Double? = cache.get(.piKey)

try t.assert(isNil: nilValue)

JSON

enum MockJSONKey: String, Hashable {
    case name, number, bool, invalid_key
}

struct MockJSON: Codable {
    var name: String
    var number: Int
    var bool: Bool
}

let jsonData: Data = try! JSONEncoder().encode(MockJSON(name: "Twitch", number: 5, bool: false))

let json: c.JSON<MockJSONKey> = .init(data: jsonData)

XCTAssertEqual(try! json.resolve(.name), "Twitch")
XCTAssertEqual(try! json.resolve(.number), 5)
XCTAssertEqual(try! json.resolve(.bool), false)

let invalid_key: Bool? = json.get(.invalid_key)

XCTAssertNil(json.get(.invalid_key))
XCTAssertNil(invalid_key)

json.set(value: "Leif", forKey: .name)

XCTAssertEqual(try! json.resolve(.name), "Leif")

Global Cache

let someCache: Cache = ...

// Set the value of a Cache with any hashable key
c.set(value: someCache, forKey: "someCache")

// Get an optional Cache using any hashable key
let anotherCache: Cache? = c.get(0)

// Require that a Cache exist using a `.get` with a force unwrap
let requiredCache: Cache = try c.resolve(0)

let keyedCache: KeyedCache<String> = try c.resolve(...)

Changes: 1a211c6

1.2.0

19 Oct 22:48
96ecba0

Choose a tag to compare

What's Changed

Full Changelog: 1.1.1...1.2.0

1.1.1

17 May 23:35

Choose a tag to compare

Fixed

  • Access type for MissingRequiredKeysError init

Added

  • contains: Checks if the given key has a value or not
  • require: Checks to make sure the cache has the required keys, otherwise it will throw an error
  • valuesInCache: Returns a Dictionary containing only the key value pairs where the value is the same type as the generic type Value

What's Changed

Full Changelog: 1.1.0...1.1.1

1.1.0

17 May 23:30
7359117

Choose a tag to compare

Added

  • contains: Checks if the given key has a value or not
  • require: Checks to make sure the cache has the required keys, otherwise it will throw an error
  • valuesInCache: Returns a Dictionary containing only the key value pairs where the value is the same type as the generic type Value

What's Changed

Full Changelog: 1.0.1...1.1.0

1.0.1

06 May 19:50

Choose a tag to compare

Full Changelog: 1.0.0...1.0.1

1.0.0

06 May 19:42

Choose a tag to compare

c

Micro Composition

What is c?

c is a simple composition framework. You have the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved.

Where can c be used?

c can be used anywhere to create transformations or interact with the cache.

Examples

BiDirectionalTransformation of String and Int

let transformer = c.transformer(
    from: { string in Int(string) },
    to: { int in "\(String(describing: int))" }
)

let string = transformer.to(3)
let int = transformer.from("3")

try t.assert(transformer.to(int), isEqualTo: string)

Cache

let cache = c.Cache()

cache.set(value: Double.pi, forKey: "🥧")

let pi: Double = cache.get("🥧") ?? 0

try t.assert(pi, isEqualTo: .pi)

let resolvedValue: Double = cache.resolve("🥧")

try t.assert(resolvedValue, isEqualTo: .pi)
                    
cache.remove("🥧")

let nilValue: Double? = cache.get("🥧")

try t.assert(isNil: nilValue)

KeyedCache

enum CacheKey: Hashable { ... }

let cache = c.KeyedCache<CacheKey>()

cache.set(value: Double.pi, forKey: CacheKey.piKey)

let pi: Double = cache.get(.piKey) ?? 0

try t.assert(pi, isEqualTo: .pi)

let resolvedValue: Double = cache.resolve(.piKey)

try t.assert(resolvedValue, isEqualTo: .pi)
                    
cache.remove(.piKey)

let nilValue: Double? = cache.get(.piKey)

try t.assert(isNil: nilValue)

JSON

enum MockJSONKey: String, Hashable {
    case name, number, bool, invalid_key
}

struct MockJSON: Codable {
    var name: String
    var number: Int
    var bool: Bool
}

let jsonData: Data = try! JSONEncoder().encode(MockJSON(name: "Twitch", number: 5, bool: false))

let json: c.JSON<MockJSONKey> = .init(data: jsonData)

XCTAssertEqual(json.resolve(.name), "Twitch")
XCTAssertEqual(json.resolve(.number), 5)
XCTAssertEqual(json.resolve(.bool), false)

let invalid_key: Bool? = json.get(.invalid_key)

XCTAssertNil(json.get(.invalid_key))
XCTAssertNil(invalid_key)

json.set(value: "Leif", forKey: .name)

XCTAssertEqual(json.resolve(.name), "Leif"

Global Cache

let someCache: Cache = ...

// Set the value of a Cache with any hashable key
c.set(value: someCache, forKey: "someCache")

// Get an optional Cache using any hashable key
let anotherCache: Cache? = c.get(0)

// Require that a Cache exist using a `.get` with a force unwrap
let requiredCache: Cache = c.resolve(0)

let keyedCache: KeyedCache<String> = c.resolve(...)

Full Changelog: 0.4.0...1.0.0