HaxeDoc2

(やまだぃちぅ) #1
WhileStringdoes not have areplacefunctionality by itself, theusing StringTools
static extension provides one. As usual, the Javascript output nicely shows the transformation:

1 Main.main = function() {
2 StringTools.replace("adc","d","b");
3 }


The following classes from the Haxe Standard Library are designed to be used as static exten-
sions:

StringTools:Provides extended functionality on strings, such as replacing or trimming.

Lambda: Provides functional methods on iterables.

haxe.EnumTools:Provides type information functionality on enums and their instances.

haxe.macro.Tools:Provides different extensions for working with macros (seeTools(Sec-
tion 9.4)).

Trivia: “using” using
Since theusingkeyword was added to the language, it has been common to talk about
certain problems with “using using” or the effect of “using using”. This makes for awkward
English in many cases, so the author of this manual decided to call the feature by what it
actually is: Static extension.

6.4 Pattern Matching


6.4.1 Introduction.....................................


Pattern matching is the process of branching depending on a value matching given, possibly
deep patterns. In Haxe, all pattern matching is done within aswitchexpression (5.17) where
the individualcaseexpressions represent the patterns. Here we will explore the syntax for
different patterns using this data structure as running example:

1 enum Tree{
2 Leaf(v:T);
3 Node(l:Tree, r:Tree);
4 }


Some pattern matcher basics include:


  • Patterns will always be matched from top to bottom.

  • The topmost pattern that matches the input value has its expression executed.

  • Apattern matches anything, socase : is equal todefault:


6.4.2 Enum matching...................................


Enums can be matched by their constructors in a natural way:
Free download pdf