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

Scala example source code file (ArrowUsage.scala)

This example Scala source code file (ArrowUsage.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

app, arrowusage, int, string

The ArrowUsage.scala Scala example source code

package scalaz.example

import scalaz._

object ArrowUsage extends App {

  import Scalaz._

  val plus1 = (_: Int) + 1
  val times2 = (_: Int) * 2
  val rev = (_: String) reverse

  // Function1 arrow

  // Applying first on the Function1 arrow.
  (plus1.first apply (7, "abc")) assert_=== (8, "abc")

  // Applying second on the Function1 arrow.
  (plus1.second apply ("def", 14)) assert_=== ("def", 15)

  // Combine plus1 and rev on the Function1 arrow to apply across both elements of a pair.
  (plus1 *** rev apply (7, "abc")) assert_=== (8, "cba")

  // Perform both plus1 and times2 on a value using the Function1 arrow
  (plus1 &&& times2 apply 7) assert_=== (8, 14)

  // Perform plus1 on a pair using the Function1 arrow
  (plus1.product apply (9, 99)) assert_=== (10, 100)


Other Scala examples (source code examples)

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