|
Scala example source code file (ArrowUsage.scala)
The ArrowUsage.scala Scala example source codepackage 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 |
Copyright 1998-2024 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.