pr1001/pf.js
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
pf.js is a simple Javascript library that attempts to implement partial functions in a format akin to those found in Scala. Specifically this means that each partial function is a function that only returns something for a discrete set of values. Further reading: http://www.scala-lang.org/node/134 http://suereth.blogspot.com/2008/11/using-partial-functions-and-pattern.html http://en.wikipedia.org/wiki/Partial_function An example: var myCondition = Condition(1, function() { return "one" }); var myPF = PF(myCondition) myPF.isDefinedAt(1) // -> true myPF.isDefinedAt("dog") // -> false myPF(1) // -> "one" myPF("dog") // -> error thrown var anotherCondition = Condition("dog", function() { return "man's best friend" }); var anotherPF = PF(anotherCondition) var thirdPF = myPF.orElse(anotherPF) thirdPF.isDefinedAt(1) // -> true thirdPF.isDefinedAt("dog") // -> true thirdPF(1) // -> "one" thirdPF("dog") // -> "man's best friend"
About
pf.js is a simple Javascript library that attempts to implement partial functions in a format akin to those found in Scala.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published