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
// | |
// MovieViewController.swift | |
// Acmeflix | |
// | |
// Created by Manish Katoch on 08/08/19. | |
// Copyright © 2019 Manish Katoch. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
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
import UIKit | |
import SwiftyJSON | |
class ViewController: UIViewController { | |
private let reuseIdentifier = "MovieCell" | |
private let httpClient = RestfulClient.shared | |
private var movies: [Resource<Movie>] = [] |
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
class Root: Decodable {} | |
extension Resource where T:Root { | |
func hasLibrary() -> Bool { | |
return self.hasCapability(for: "library") | |
} | |
func getLibraryLink() -> Link? { | |
return self.getRelation(forRel: "library") | |
} |
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 Link : Decodable, Equatable { | |
let url: String | |
let rel: String | |
let method: HttpMethod | |
let bodyJson: [String: DecodableValueType]? | |
enum CodingKeys: String,CodingKey { | |
case url = "href" | |
case rel, method |
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
// | |
// HttpClient.swift | |
// Acmeflix | |
// | |
// Created by Manish Katoch on 04/08/19. | |
// Copyright © 2019 Manish Katoch. 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
typealias LinkAvailableHandler = (Link) -> Void | |
typealias LinkUnAvailableHandler = () -> Void | |
protocol RestResource: Decodable { | |
associatedtype modelType where modelType : Decodable | |
var item: modelType? {get} | |
var links: Array<Link> { get } | |
} | |
extension RestResource { |
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
// simple Member class | |
case class Member(id: String, name: String, points: Long) | |
// member types | |
trait MemberType {val member: Member} | |
case class FirstTimer(member: Member) extends MemberType | |
case class FrequentShopper(member: Member) extends MemberType | |
case class Patron(member: Member) extends MemberType | |
// membership card |
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
trait Discounted[T] { | |
def getDiscount: Double | |
} | |
object Discounted { | |
// apply method called by compiler to instantiate if no instance found | |
def apply[T](implicit discounted: Discounted[T]) = discounted | |
def createDiscounted[T](fn: () => Double) = new Discounted[T] { | |
override def getDiscount: Double = fn() | |
} |
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
object syntax { | |
implicit class RichDataSet[A](dataSet: Dataset[A]) { | |
val enriched: RichDataSet[A] = this | |
def apply[K](column: Witness.Lt[Symbol])(implicit lhsExists: PropertyExists[A, column.T, K]): Column = | |
new Column(column.value.name) | |
def leftJoin[B, K](withDataSet: Dataset[B]): JoinDataSet[A, B] = JoinDataSet.leftJoin(dataSet, withDataSet) |
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
@implicitNotFound(msg = "${PName} not found in ${T}") | |
trait PropertiesExists[T, PName <: HList, PType] | |
object PropertiesExists { | |
implicit def forHNil[T, PName, PType]( | |
implicit head: PropertyExists[T, PName, PType]): PropertiesExists[T, PName :: HNil, PType] = | |
new PropertiesExists[T, PName :: HNil, PType] {} | |
implicit def forHList[T, PNameHead, PNameTail <: HList, PTypeForHead, PTypeForTail]( | |
implicit headExists: PropertyExists[T, PNameHead, PTypeForHead], |
NewerOlder