| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (StringOps.scala)

This example Scala source code file (StringOps.scala) is included in the "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

anyval, bigdecimal, bigint, boolean, byte, double, float, int, long, nonemptylist, short, string, stringops, validation

The StringOps.scala Scala example source code

package scalaz
package syntax
package std

import scalaz.std.{string => s}

final class StringOps(val self: String) extends AnyVal {
   * Returns the same String value if the given value is 1 otherwise pluralises this String by appending an "s" unless
   * this String ends with "y" and not one of ["ay", "ey", "iy", "oy", "uy"] in which case the 'y' character is chopped and "ies"
   * is appended.
  def plural(n: Long): String = s.plural(self, n)

   * Constructs a non-empty list with the value if it is not empty, otherwise, throws an error.
  def charsNel : Option[NonEmptyList[Char]] = s.charsNel(self)

   * Constructs a non-empty list with the given string if it is not empty, otherwise, returns the second argument.
  def charsNel(e: => NonEmptyList[Char]) : NonEmptyList[Char] = s.charsNel(self, e)

  // Parsing functions.

  def parseBoolean: Validation[IllegalArgumentException, Boolean] = s.parseBoolean(self)

  def parseByte: Validation[NumberFormatException, Byte] = s.parseByte(self)

  def parseShort: Validation[NumberFormatException, Short] = s.parseShort(self)

  def parseInt: Validation[NumberFormatException, Int] = s.parseInt(self)

  def parseLong: Validation[NumberFormatException, Long] = s.parseLong(self)

  def parseFloat: Validation[NumberFormatException, Float] = s.parseFloat(self)

  def parseDouble: Validation[NumberFormatException, Double] = s.parseDouble(self)

  def parseBigInt: Validation[NumberFormatException, BigInt] = s.parseBigInt(self)

  def parseBigDecimal: Validation[NumberFormatException, BigDecimal] = s.parseBigDecimal(self)

trait ToStringOps {
  implicit def ToStringOpsFromString(a:String): StringOps = new StringOps(a)

Other Scala examples (source code examples)

Here is a short list of links related to this Scala StringOps.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,
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.