alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (IsEmpty.scala)

This example Scala source code file (IsEmpty.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

boolean, isempty, isemptylaw, plusempty

The IsEmpty.scala Scala example source code

package scalaz

////
/**
 * Typeclass that permits testing whether some type with an empty representation
 * is in fact empty.
 */
////
trait IsEmpty[F[_]] extends PlusEmpty[F] { self =>
  ////
  def isEmpty[A](fa: F[A]): Boolean

  // derived functions

  trait IsEmptyLaw extends EmptyLaw {
    def emptyIsEmpty[A]: Boolean = isEmpty(empty[A])

    def emptyPlusIdentity[A](f1: F[A], f2: F[A]): Boolean =
      (isEmpty(f1) && isEmpty(f2)) == isEmpty(plus(f1, f2))
  }

  def isEmptyLaw = new IsEmptyLaw {}

  ////
  val isEmptySyntax = new scalaz.syntax.IsEmptySyntax[F] { def F = IsEmpty.this }
}

object IsEmpty {
  @inline def apply[F[_]](implicit F: IsEmpty[F]): IsEmpty[F] = F

  ////

  ////
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala IsEmpty.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.