Skip to content

Instantly share code, notes, and snippets.

View oleksii-demedetskyi's full-sized avatar
🎯
Arrow: Language for unidirectional programming

Oleksii Demedetskyi oleksii-demedetskyi

🎯
Arrow: Language for unidirectional programming
View GitHub Profile
class Subscription<T> {
func perform(callback: () -> Void) {
}
func notify() {
}
}
import Cocoa
struct State {
var posts: [Post.ID: Post]
var users: [User.ID: User]
var currentUser: User.ID?
}
struct Post {
This file has been truncated, but you can view the full file.
{
"name": "total",
"start": 0,
"duration": 55799,
"nested": [
{
"name": "sort",
"start": 17,
"duration": 27749,
"nested": [
@oleksii-demedetskyi
oleksii-demedetskyi / ReduceComponents.swift
Last active August 9, 2019 10:38
Combine reducers together with state that they are represent into single structure.
//
// main.swift
// ReducerComponents
//
// Created by Alexey Demedetskii on 6/19/19.
// Copyright © 2019 Sigma software. All rights reserved.
//
import Foundation
@oleksii-demedetskyi
oleksii-demedetskyi / Reader.swift
Created June 18, 2019 09:34
Proxy object for registering object reads.
import Cocoa
protocol ImplicitlyConvertible {
associatedtype ConversionResult
func convert() -> ConversionResult
}
@dynamicMemberLookup
struct Reader<State>: ImplicitlyConvertible {
let state: State
@oleksii-demedetskyi
oleksii-demedetskyi / Draft.swift
Created June 15, 2019 19:47
Allows updates even to let constants and tracking of updates
import Cocoa
protocol Primitive {}
extension Int: Primitive {}
@dynamicMemberLookup
struct Draft<Value> {
let value: Value
var updates: [PartialKeyPath<Value>: Any] = [:]
protocol _Reducer {
associatedtype State
associatedtype Action
func reduce(state: inout State, action: Action)
}
protocol Reducer: _Reducer where State == Body.State, Action == Body.Action {
associatedtype Body: Reducer
@oleksii-demedetskyi
oleksii-demedetskyi / ReducerBuidler.swift
Created June 12, 2019 12:48
Redux reducer composed using new @functionBuilder api
protocol Action {}
struct Reducer<State> {
let reduce: (State, Action) -> State
}
struct Increment: Action {}
struct Decrement: Action {}
func on<State, A>(_ actionType: A.Type, reduce: @escaping (State, A) -> State) -> Reducer<State> {
//: Playground - noun: a place where people can play
import Cocoa
class Observation<T>: Hashable {
var hashValue: Int {
return ObjectIdentifier(self).hashValue
}
static func ==(lhs: Observation<T>, rhs: Observation<T>) -> Bool {
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
struct Example: Codable {
let name: String
let age: Int
}