The Trunk: Kernel-tonyg.1149.mcz

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

The Trunk: Kernel-tonyg.1149.mcz

David T. Lewis uploaded a new version of Kernel to project The Trunk:

==================== Summary ====================

Name: Kernel-tonyg.1149
Author: tonyg
Time: 31 January 2018, 11:45:27.771328 pm
UUID: ab03b520-f8a0-4aa9-87c4-9b7e9dfb0369
Ancestors: Kernel-tonyg.1148

Add an alias for Promise>>#then:, called #>>=, echoing the monadic bind operator.

Use of a binary selector allows for convenient chaining of Promises without lots of nested parentheses.

For example:

        (self produceSomePromise)
        >>= [:v | self produceAnotherPromiseInvolving: v]
        >>= [:v | self makeYetAnotherUsing: v]
instead of the more cumbersome

        ((self produceSomePromise)
                then: [:v | self produceAnotherPromiseInvolving: v])
                        then: [:v | self makeYetAnotherUsing: v]

Also adds #>>, again named after the analogous monadic operator, which is like #>>= but does not pass the value from the left-hand-side promise to the continuation block.

=============== Diff against Kernel-tonyg.1148 ===============

Item was added:
+ ----- Method: Promise>>>> (in category 'monad') -----
+ >> resolvedBlock
+ "Like >>=, but discards the result of the promise."
+ ^ self then: [:v | resolvedBlock value]!

Item was added:
+ ----- Method: Promise>>>>= (in category 'monad') -----
+ >>= resolvedBlock
+ "Alias for `then:` allowing convenient chaining."
+ ^ self then: resolvedBlock!