<commit_before>/*
 * Copyright (c) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package shapeless.examples

import shapeless._

// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo /*extends App*/ {
  // Example from scala.Enumeration scaladoc. Terse ...
  object WeekDay extends Enumeration {
    type WeekDay = Value
    val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
  }

  import WeekDay._

  def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)

  assert((WeekDay.values filter isWorkingDay) == Set(Mon, Tue, Wed, Thu, Fri))

  // However ...

  def isWeekend(d: WeekDay) = d match {
    case Sat | Sun => true
    // Oops! Missing case ... still compiles
  }

  assert(!isWeekend(Mon)) // MatchError at run time
}

// A safer ADT+shapeless alternative ...
//
object ShapelessEnumDemo extends App {
  // ADT as an enumeration. A little more boilerplate ...
  sealed trait WeekDay
  object WeekDay {
    case object Mon extends WeekDay
    case object Tue extends WeekDay
    case object Wed extends WeekDay
    case object Thu extends WeekDay
    case object Fri extends WeekDay
    case object Sat extends WeekDay
    case object Sun extends WeekDay

    val values: Set[WeekDay] = Values
  }<commit_msg>Further boilerplate reduction via multi-assignement.<commit_after>/*
 * Copyright (c) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package shapeless.examples

import shapeless._

// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo /*extends App*/ {
  // Example from scala.Enumeration scaladoc. Terse ...
  object WeekDay extends Enumeration {
    type WeekDay = Value
    val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
  }

  import WeekDay._

  def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)

  assert((WeekDay.values filter isWorkingDay) == Set(Mon, Tue, Wed, Thu, Fri))

  // However ...

  def isWeekend(d: WeekDay) = d match {
    case Sat | Sun => true
    // Oops! Missing case ... still compiles
  }

  assert(!isWeekend(Mon)) // MatchError at run time
}

// A safer ADT+shapeless alternative ...
//
object ShapelessEnumDemo extends App {
  // ADT as an enumeration. Barely any more boilerplate ...
  sealed trait WeekDay
  object WeekDay {
    val Mon, Tue, Wed, Thu, Fri, Sat, Sun = new WeekDay {}
    val values: Set[WeekDay] = Values
  }
{'fraction_non_alphanumeric': 0.09465950833568805, 'fraction_numerical': 0.004521051144391071, 'mean_word_length': 3.1500586166471276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6021470', 'n_tokens_mistral': 1070, 'n_tokens_neox': 998, 'n_words': 431}