mint.function - Palamecia/mint GitHub Wiki

Module

load mint.function

This module provides tools to extend functions capabilities.

Classes

Callback

This class provides a context to call a function or a method indirectly.

Members

Modifiers Member Description
+ const != Returns true if other is not equal to this callback; otherwise returns ``...
+ const () Calls the callback with the given parameters and returns the callback's retur...
+ const == Returns true if other is equal to this callback; otherwise returns fals...
- final % function Internal function.
- @ g_lib Global library handle.
+ const getFunction Returns the callback's function or method.
+ const getObject Returns the callback's object or none if the callback is not a callback on ...
- final memberInfo Internal member informations.
+ const new Creates a new callback on the func function. The func parameter can also ...
- final object Internal object.
+ const toString Returns the callback's function or method name or a placeholder.

Signal

This class provides an evenemential callback mechanisme. Multiple callbacks can be connected to an instance using the connect method. Each connected callback will then be called on a call to the () operator.

Members

Modifiers Member Description
+ const () Calls each callbacks connected to the signal. Parameters provided to this ope...
+ const connect Connects the signal to the given func function. The func function can eit...
+ const disconnect Disconnects the signal and the given object function or object. If object...
+ const new Creates a new signal.
- final slots Internal connected slots list.

Functions

Descriptions

()

def

Callback.!=

def (const self, const other)

Returns true if other is not equal to this callback; otherwise returns false.

Two callbacks are considered equal if they calls the same function or the same method on the same object.

Callback.()

def (const self, ...)

Calls the callback with the given parameters and returns the callback's return value.

Callback.==

def (const self, const other)

Returns true if other is equal to this callback; otherwise returns false.

Two callbacks are considered equal if they calls the same function or the same method on the same object.

Callback.function

none

Internal function.

Callback.g_lib

lib ('libmint-mint')

Global library handle.

Callback.getFunction

def (const self)

Returns the callback's function or method.

Callback.getObject

def (const self)

Returns the callback's object or none if the callback is not a callback on an object member.

Callback.memberInfo

none

Internal member informations.

Callback.new

def (self, % func)

Creates a new callback on the func function.

The func parameter can also be:

  • an instance of Callback, in this case the object is returned as the new instance.
  • an object providing a toCallback method, in this case the result of this method call is used as the new instance.
  • an object providing a toFunction method, in this case the result of this method call is used to retrieve the function.

In other cases, none is returned.

def (self, object, % member)

Creates a new callback on the member member of the object object. The member can either be a member function of object or a member name.

If object has no member member, none is returned.

Callback.object

none

Internal object.

Callback.toString

def (const self)

Returns the callback's function or method name or a placeholder.

Signal.()

def (const self, ...)

Calls each callbacks connected to the signal. Parameters provided to this operator are also provided to the callbacks.

Signal.connect

def (self, func)

Connects the signal to the given func function. The func function can either be a function or an instane of Callback.

Returns true if the function was correctly connected to the signal; otherwise returs false.

def (self, object, % member)

Connects the signal to an instance of Callback using the object instance and the member method.

Returns true if the callback was correctly connected to the signal; otherwise returs false.

Signal.disconnect

def (self, % object)

Disconnects the signal and the given object function or object. If object is not a function, each connected callback that call a method on this object is disconnected.

The functions will no more be called by the signal.

Returns true if the functions were correctly disconnected from the signal; otherwise returs false.

def (self, object, % member)

Disconnects the signal and the callback using the object instance and the member method. The callback will no more be called by the signal.

Returns true if the callback was correctly disconnected from the signal; otherwise returs false.

Signal.new

def (self)

Creates a new signal.

Signal.slots

[]

Internal connected slots list.

partial

def (func, ...)

Returns a new function equivalent to func but with the extra arguments automaticaly passed as first arguments.

Example:

load mint.math
const powerOfTwo = partial(pow, 2)
powerOfTwo(3) // gives 8

partialMethod

def (func, ...)

Returns a new method equivalent to func but with the extra arguments automaticaly passed as first arguments. This function works like {see{@ partial} but keep the calling object instance as first parameter.

Example:

load mint.range
const startsWithDot = partialMethod(startsWith, '.')
'.local'.startsWithDot(3) // gives true

reduce

def (func, ...)

Returns the value of the func binary function applied cumulatively to each extra arguments.