Git Product home page Git Product logo

primer's Introduction

Primer Swift

Assign

This function is used to copy the values of all enumerable own properties from one or more source struct to a target struct. If the argument is a reference type the same refence is returned.

public func assign<T>(_ value: T, changes: (inout T) -> Void) -> T

Partial

Constructs a type with all properties of T set to optional. This utility will return a type that represents all subsets of a given type.

The wrapped type can be then constructed at referred time by calling the build() method. The instance can be later on changed with the merge(inout _:) method.

struct Todo { var title: String; var description: String } 
var partial = Partial { .success(Todo(
 title: $0.get(\Todo.title, default: "Untitled"),   
 description: $0.get(\Todo.description, default: "No description"))) 
} 
partial.title = "A Title" 
partial.description = "A Description" 
var todo = try! partial.build().get() 
partial.description = "Another Descrition" 
todo = partial.merge(&todo) 

ReadOnly

Constructs a type with all properties of T set to readonly, meaning the properties of the constructed type cannot be reassigned.

Note A read-only object can propagate change events if the wrapped type ia an ObservableObject by calling propagateObservableObject() at construction time.

struct Todo { var title: String; var description: String }
let todo = Todo(title: "A Title", description: "A Description")
let readOnlyTodo = ReadOnly(todo)
readOnlyTodo.title // "A title"

ObservableProxy

Creates an observable Proxy for the object passed as argument (with granularity at the property level).

struct Todo { var title: String; var description: String }
let todo = Todo(title: "A Title", description: "A Description")
let proxy = Proxy(todo)
proxy.propertyDidChange.sink {
  if $0.match(keyPath: \.title) {
    ...
  }
}
proxy.title = "New Title"

Concurrency

This package offer a variety of different lock implementations:

  • Mutex: enforces limits on access to a resource when there are many threads of execution.
  • UnfairLock: low-level lock that allows waiters to block efficiently on contention.
  • ReadersWriterLock: readers-writer lock provided by the platform implementation of the POSIX Threads standard.

Property wrappers to work with any of the locks above or any NSLocking compliant lock:

  • @LockAtomic<L: Locking>
  • @SyncDispatchQueueAtomic
  • @ReadersWriterAtomic

The package also includes LockfreeAtomic: fine-grained atomic operations allowing for Lockfree concurrent programming. Each atomic operation is indivisible with regards to any other atomic operation that involves the same object.

primer's People

Contributors

alexdrone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.