 	return { l in l.map(f) }
 }
 
+/// Maps a function over a list and returns a new list containing the mapped values.
+public func map<A, B>(f : A -> B) -> List<A> -> List<B> {
+	return { l in l.map(f) }
+}
+
 /// Replace all occurrences of a value in a list by another value.
 public func replace<A : Equatable>(x : A) -> A -> [A] -> [A] {
+	return { y in { xs in xs.map({ z in z == x ? y : z }) } }
+}
+
+/// Replace all occurrences of a value in a list by another value.
+public func replace<A : Equatable>(x : A) -> A -> List<A> -> List<A> {
 	return { y in { xs in xs.map({ z in z == x ? y : z }) } }
 }
 

		case .Nil:
			return []
		case .Cons(let x, let xs):
			return [x] <| foldr({ (let ys : [A]) in
				return { r in
					return ys <| (x <| ys) <| r
				}
			})([])(nonEmptySubsequences(xs))
	}
}



}

private func select<A>(p : A -> Bool) -> A -> ([A], [A]) -> ([A], [A]) {
	return { x in { t in p(x) ? (x <| fst(t), snd(t)) : (fst(t), x <| snd(t)) } }
}

/// Partitions the elements of a list according to a predicate.
///
/// partition({ $0 < 3 })([1, 2, 3, 4, 5]) == ([1, 2],[3, 4, 5])
public func partition<A>(p : A -> Bool) -> List<A> -> (List<A>, List<A>) {
	let e = (List<A>(), List<A>())
	return { l in foldr(select(p))(e)(l) }
}

private func select<A>(p : A -> Bool) -> A -> (List<A>, List<A>) -> (List<A>, List<A>) {
	return { x in { t in p(x) ? (x <| fst(t), snd(t)) : (fst(t), x <| snd(t)) } }
}

