Skip to content

Instantly share code, notes, and snippets.

I want Swift's Either like ...

Suppose that Either is declared in the following way,

enum Either<T, U> {
    case Left(T)
    case Right(U)
}
@koher
koher / gist:c8db7b243e2ad347a165
Created June 23, 2015 02:16
Higher-oder functions/methods vs Control statements
a.map { b in
b.map { c in {
foo(b, c)
}
}
for b in a {
for c in b {
foo(b, c)
}
@koher
koher / gist:81c3d71a03c5caaed515
Created September 19, 2014 17:43
Javaで?を使わずにListがCovariantであるように振る舞わせると・・・
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.lang.System.out;
public class VarianceTest {
static class Animal {
}
@koher
koher / gist:834e0e8b5a19d316b1cf
Created June 22, 2014 11:28
Conceptual Implementations of Swift's Array and Dictionary
struct Array2<T> {
var buffer: Buffer<T>
var count: Int
init() {
buffer = Buffer()
count = 0
}
init(_ elements: T...) {
@koher
koher / gist:617a51f3474a9ffc157b
Last active August 29, 2015 14:02
Swift's Polymorphism Test
protocol O {
func f() -> String
}
struct A : O {
func f() -> String {
return "a"
}
}
@koher
koher / MultiValuesTestServlet.java
Created March 26, 2010 11:50
GAE/JのLow-Level APIで複数値プロパティを扱う例
package org.koherent.appengine.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.ServletException;