Maybe:
Filter:
Classes | JITLib > Environments | Live Coding

Maybe : Ref : AbstractFunction : Object

referentially transparent proxy object
Source: Fdef.sc
Subclasses: Fdef

Description

A Maybe object can contain either nil or some other object, and allows to construct calculations without knowing this other object yet. If the calculation fails, due to a loop or a not yet defined object, Maybe returns nil.

The name Maybe stems from the programming language Haskell, where it represents a somewhat similar entity. See also: Fdef

NOTE: A Maybe object lazily constructs an operation as an object instead of performing it immediately. Its implementation remains incomplete necessarily, in the current form: it is limited to the arithmetic operations that AbstractFunction implements and the following collection methods: put, addAll, add, putAll, atAll.

You can extend Maybe as you need for your purpose, by the following schema:

Class Methods

Maybe.new(thing)

From superclass: Ref

create a new instance

Arguments:

thing

an object or nil.

Inherited class methods

Undocumented class methods

Maybe.callFunc

Maybe.callFunc = value

Maybe.callers

Maybe.current

Maybe.defaultValue

Maybe.defaultValue = value

Maybe.protected

Maybe.protected = value

Maybe.verbose

Maybe.verbose = value

Instance Methods

.source

.source = obj

return or set the contained object

.value

.value = value

set the contained object or return the source, or the value of the contained object, if it is a Maybe. If there is a recursion, return nil.

.apply( ... args)

return the value, or the value of the contained object, if it is a Maybe. This method allows recursion, so that recursive calculations can be made.

.doesNotUnderstand(selector ... args)

(called by any message that Maybe doesn't understand.)

returns a composition function that, when evaluated, returns the value.

Inherited instance methods

Undocumented instance methods

<>(that)

.add( ... args)

.addAll( ... args)

.all

.at( ... args)

.atAll( ... args)

.catchRecursion(func)

.clear

.composeBinaryOp(aSelector, something, adverb)

.composeNAryOp(aSelector, anArgList)

.composeUnaryOp(aSelector)

.do(function)

.embedInStream(inval)

.findKey

.functionPerformList(selector, arglist)

.includedInCallers

.infoString(args)

.o( ... args)

.postString

.put( ... args)

.putAll( ... args)

.reduceFuncProxy(args, protect: true)

.reverseComposeBinaryOp(aSelector, something, adverb)

.valueArray(args)

.valueArrayEnvir( ... args)

.valueEnvir( ... args)

.valueFuncProxy(args)

Examples