<commit_before>//
//  determined.swift
//  deferred
//
//  Created by <NAME> on 9/26/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

public struct Determined<Value>
{
  private let state: State<Value>

  init(_ value: Value)
  {
    state = .value(value)
  }

  init(_ error: Error)
  {
    state = .error(error)
  }

  public func get() throws -> Value
  {
    switch state
    {
    case .value(let value): return value
    case .error(let error): throw error
    }
  }

  public var value: Value? {
    if case .value(let value) = state { return value }
    return nil
  }

  public var error: Error? {
    if case .error(let error) = state { return error }
    return nil
  }

  public var isValue: Bool {
    if case .value = state { return true }
    return false
  }

  public var isError: Bool {
    if case .error = state { return true }
    return false
  }
}

private enum State<Value>
{
  case value(Value)
  case error(Error)
}<commit_msg>conditionally conform Determined to Equatable<commit_after>//
//  determined.swift
//  deferred
//
//  Created by <NAME> on 9/26/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

public struct Determined<Value>
{
  private let state: State<Value>

  init(_ value: Value)
  {
    state = .value(value)
  }

  init(_ error: Error)
  {
    state = .error(error)
  }

  public func get() throws -> Value
  {
    switch state
    {
    case .value(let value): return value
    case .error(let error): throw error
    }
  }

  public var value: Value? {
    if case .value(let value) = state { return value }
    return nil
  }

  public var error: Error? {
    if case .error(let error) = state { return error }
    return nil
  }

  public var isValue: Bool {
    if case .value = state { return true }
    return false
  }

  public var isError: Bool {
    if case .error = state { return true }
    return false
  }
}

#if swift (>=4.1)
extension Determined: Equatable where Value: Equatable
{
  public static func ==(lhs: Determined, rhs: Determined) -> Bool
  {
    switch (lhs.state, rhs.state)
    {
    case (.value(let lhv), .value(let rhv)): return lhv == rhv
    default: return false // assume that error states are never equal
    }
  }
}
#endif

private enum State<Value>
{
  case value(Value)
  case error(Error)
}
{'fraction_non_alphanumeric': 0.11595466434176112, 'fraction_numerical': 0.008718395815170008, 'mean_word_length': 2.4563253012048194, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '7226274', 'n_tokens_mistral': 792, 'n_tokens_neox': 748, 'n_words': 255}