Created With

linkFeatures

On this page are only some features listed, for a complete overview please see the API documentation.

linkData and mutability

All functions are handling Arrays and other types as immutable (unless explicitly specified).

1var inputArray = [6, 9]

2var outputArray = G(inputArray).map(GG.id).val # new array equal to [6, 9]

linkFunctions

Most functions/methods should support following types when expecting a function (referred to as function-like/FunctionLike):

linkComposition

linkPipe

A pipe accepts an input value and a pipeline (Array of function-like). An input value is passed to the first function, result of the first function is passed to the second function and so on, until the last function which result is returned from the pipe function as a final result.

1# Take 3 first words and capitalize them

2

3var text_input = "Morbi id mauris pep erisus. Aenean."

4

5var three_words_capitalized = GG.pipe_(text_input, [\

6 GG.words_raw, # ["Morbi", "id", "mauris", "pep", "erisus.", "Aenean."]

7 [GG.take, 3], # ["Morbi", "id", "mauris"]

8 [GG.map, GG.capitalize], # ["Morbi", "Id", "Mauris"]

9 GG.unwords # "Morbi Id Mauris"

10])

11assert(three_words_capitalized == "Morbi Id Mauris")

linkFlow

Similar to a pipe function, but instead of immediately doing computation, flow returns a "function" (callable object instance with a similar interface as FuncRef) which behaves as it would be composed of all functions in a passed pipeline. flow is commonly known as a reverse composition operator (e.g. >>> in Haskell).

linkFunction utilities

linkObject and dictionary utilities

linkArray utilities

Array utilities known from other dynamic and/or functional languages. Golden Gagdet also contains an array wrapper with fluent API - GGArray - to streamline working with arrays. some examples:

linkGGArray

1var monsters = [

2 Monster.new(0, "Orc"), # hp, name

3 Monster.new(5, "Demon"),

4 Monster.new(12, "Amus"),

5 Monster.new(0, "Borg"),

6]

7

8# Names of Weak and Alive monsters example

9

10# imperative solution

11var weak_alive_monsters_imperative = []

12for monster in monsters:

13 if monster.is_alive && monster.hp < 10:

14 weak_alive_monsters_imperative.push_back(monster.name)

15

16# functional approach, uses lambdas (anonymous functions)

17var weak_alive_monsters =

18 G(monsters).filter("x => x.is_alive && x.hp < 10").map("x => x.name").val

19

20assert(weak_alive_monsters_imperative == ["Demon"])

21assert(weak_alive_monsters == ["Demon"])

linkMultidimensional arrays

1GG.new_array_("x", [2, 3]) # [["x", "x", "x"], ["x", "x", "x"]]

2GG.generate_array_("x => x[0] * 10 + x[1]", [2, 3]) # [ [0, 1, 2], [10, 11, 12] ]

linkString utilities

String helpers like words, unwords, lines, unlines, join.

linkNumber utilities

linkFormatting

1GG.format_float_2_(1.23456) # "1.23"

2GG.format_vec2_2_(Vector2(1.2345, 0)) # "1.23, 0.00"

3GG.format_vec3_2_(Vector3(1.2345, 0, 7)) # "1.23, 0.00, 7.00"

linkRandom data generation

linkNode utilities

linkDrawing

linkdebug_draw_2d

Allows drawing of 2D debug shapes which will remain drawn for specific amount of time.

1# draw a red dot on global position 300 100 which stays rendered for two seconds

2GG.debug_draw_2d.point(Vector2(300, 100), Color.red)

Shapes: point, line, rect, rect_wire, string, ellipse, ellipse_wire, arrow. See GGTestsDebugDraw/GGTestsDebugDraw.gd for more examples.

linkOther

Various utility functions, few examples:

FeaturesData and mutabilityFunctionsCompositionPipeFlowFunction utilitiesObject and dictionary utilitiesArray utilitiesGGArrayMultidimensional arraysString utilitiesNumber utilitiesFormattingRandom data generationNode utilitiesDrawingdebug_draw_2dOther

Home Features Installation API Notes


[Test](/test)