Skip to content

Instantly share code, notes, and snippets.

@hsavit1
hsavit1 / ArrayHelpers.swift
Created January 1, 2016 21:31 — forked from calebd/ArrayHelpers.swift
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@hsavit1
hsavit1 / frp.md
Created December 30, 2015 06:12 — forked from ohanhi/frp.md
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Foreword

@hsavit1
hsavit1 / cont.swift
Created December 19, 2015 01:59 — forked from sjoerdvisscher/cont.swift
The mother of all monads to the rescue
// See http://blog.sigfpe.com/2008/12/mother-of-all-monads.html
// MARK: function composition
infix operator >>> { associativity left }
func >>> <A, B, C>(f: A -> B, g: B -> C) -> A -> C {
return { x in g(f(x)) }
}
// MARK: Continuation monad
struct Cont<R, A> {
@hsavit1
hsavit1 / Category.swift
Created December 17, 2015 23:55 — forked from CodaFi/Category.swift
Because I could
//
// Category.swift
// Swift_Extras
//
// Created by Robert Widmann on 9/7/14.
// Copyright (c) 2014 Robert Widmann. All rights reserved.
//
import Foundation
//
// Yoneda.swift
// Basis
//
// Created by Robert Widmann on 12/11/14.
// Copyright (c) 2014 Robert Widmann. All rights reserved.
//
import Basis
@hsavit1
hsavit1 / algebra.swift
Created December 17, 2015 23:31 — forked from sritchie/algebra.swift
Typeclasses in Swift
// Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
// Here's take 1. First, I defined the algebra like I would in
// Scala, as separate protocols:
protocol Semigroup {
typealias T
@hsavit1
hsavit1 / Example.Swift
Created December 17, 2015 23:05 — forked from dbworku/Example.Swift
Swift-ful idiomatic extensions of dispatch_semaphore_t
//
// Example.swift
//
// Created by Daniel Worku on 11/16/15.
//
// The MIT License (MIT)
// Copyright (c) 2014 Daniel Worku
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
@hsavit1
hsavit1 / Expression.swift
Created December 17, 2015 20:52
Full code listing for a post
enum Expression<Recur> {
case Variable(String)
case Abstraction(String, Recur)
case Application(Recur, Recur)
func map<Other>(transform: Recur -> Other) -> Expression<Other> {
switch self {
case let .Variable(x):
return .Variable(x)
case let .Abstraction(x, body):
@hsavit1
hsavit1 / jargon.md
Created December 17, 2015 17:44 — forked from cb372/jargon.md
Category theory jargon cheat sheet

Category theory jargon cheat sheet

A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)

I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.

Functor

A functor is something that supports map.

@hsavit1
hsavit1 / read.swift
Created December 17, 2015 03:39 — forked from erica/read.swift
import Foundation
#if os(OSX)
import Darwin
#else
import Glibc
#endif
let path = __FILE__
public struct ReadError : ErrorType {let reason: String}