This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| prefix operator ¬ | |
| prefix func ¬ (op: Bool) -> Bool { | |
| return !op | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NaiveTree.swift | |
| // immutable_nary_tree | |
| // | |
| // Created by zephyz on 18.02.17. | |
| // Copyright © 2017 moe.zephyz. All rights reserved. | |
| // | |
| import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func parse(source: String) -> Person? { | |
| func startingIndex(`for` string: String, after offset: Int) -> String.Index { | |
| return string.index(string.startIndex, offsetBy: offset) | |
| } | |
| let lines = source.components(separatedBy: "\n") | |
| guard lines.count >= 4 else { return nil } | |
| var age: Int? = nil | |
| if lines[1].hasPrefix("age: ") { | |
| let start = startingIndex(for: lines[1], after: 5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func parse(source: String) -> Person? { | |
| let lines = source.components(separatedBy: "\n") | |
| let age = matches(for: "(?<=age: )[0-9]+", in: lines[1]).flatMap({Int($0)}) | |
| let name = matches(for: "(?<=name: )\\w+", in: lines[2]) | |
| let city = matches(for: "(?<=city: )[\\w ]+", in: lines[3]) | |
| if let a = age, let n = name, let c = city { | |
| return Person(name: n, age: a, city: c) | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Person { | |
| let name: String | |
| let age: Int | |
| let city: String | |
| } |
NewerOlder