<commit_before>//
//  List.swift
//  swiftz
//
//  Created by <NAME> on 3/06/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

class Box<T> {
    let value : () -> T
    init(_ value : T) {
        self.value = { value }
    }
}

enum List<A> {
    case Nil
    case Cons(A, Box<List<A>>)

    init() {
        self = .Nil
    }
    init(_ head : A, _ tail : List<A>) {
        self = .Cons(head, Box(tail))
    }
}

func==<A : Equatable>(lhs : List<A>, rhs : List<A>) -> Bool {
    switch (lhs, rhs) {
    case (.Nil, .Nil):
        return true
    case let (.Cons(lHead, lTail), .Cons(rHead, rTail)):
        return lHead == rHead && lTail.value() == rTail.value()
    default:
        return false
    }<commit_msg>added safeHead and safeTail to List<commit_after>//
//  List.swift
//  swiftz
//
//  Created by <NAME> on 3/06/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

class Box<T> {
    let value : () -> T
    init(_ value : T) {
        self.value = { value }
    }
}

enum List<A> {
    case Nil
    case Cons(A, Box<List<A>>)

    init() {
        self = .Nil
    }
    init(_ head : A, _ tail : List<A>) {
        self = .Cons(head, Box(tail))
    }
    
    func safeHead() -> A? {
        switch self {
        case .Nil:
            return nil
        case let .Cons(head, _):
            return head
        }
    }
    
    func safeTail() -> List<A>? {
        switch self {
        case .Nil:
            return nil
        case let .Cons(_, tail):
            return tail.value()
        }
    }
}

func==<A : Equatable>(lhs : List<A>, rhs : List<A>) -> Bool {
    switch (lhs, rhs) {
    case (.Nil, .Nil):
        return true
    case let (.Cons(lHead, lTail), .Cons(rHead, rTail)):
        return lHead == rHead && lTail.value() == rTail.value()
    default:
        return false
    }
{'fraction_non_alphanumeric': 0.1650326797385621, 'fraction_numerical': 0.011982570806100218, 'mean_word_length': 1.6507936507936507, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '610315', 'n_tokens_mistral': 686, 'n_tokens_neox': 655, 'n_words': 176}