CodeFoo
This page describes some of the most useful additions for Smalltalk, you can find more of them in the CodeFooDevelopment bundle on How to access the SCG visualworks store.
Symbol » value: anObject
The simplest little extension that could possibly make a big difference. The extension allows to use symbols as unary blocks, for example you may replace
coll do: \[ :each | each unaryMessage ]
with
coll do: #unaryMessage
There is a package SymbolValue both on How to access the SCG visualworks store as well as public store. For more information, please refer to How valueable is a Symbol? by Travis Griggs.
* » asSortBlock
Answer a sort block based on the receiver, implemented as
Please note that, to improve execution speed, CodeFoo's actual implementation does some magic to generate an unbound block rather than a full block bound the receiver.
BlockClosure » *
Other useful extensions of blocks includes
assertcull: argumentshaltIfTruemillisecondsToRunprofile
Character » isSpace
Answer whether the receiver is a space.
CharacterArray » *
Useful extensions of strings includes
asCapitalizedasPlurallastWordlineslinesDo: aBlockpiecesCutWhereCamelCasetrimQuotestrimSeparatorswithIndefiniteArticle
in particular those dealing with pre- and suffices are very useful
endsWith: aStringremoveSuffix: aStringremovePrefix: aStringreplaceSuffix: aString with: newSuffixstartsWith: aString
Collection » transitiveClosure: unaryBlock
Answer the transitive closure of the receiver, that is, all elements in the receiver plus any element reachable using the unary block. For example
(Array with: Object) transitiveClosure: \[ :each | each subclasses ]
returns the same as
Object withAllSubclasses
Implemented as follows
Please not that the term closure in "transitive closure" refers to the mathematics meaning of transitive closure (see Wikipedia) rather than to computer science terminology, this is very confusing and a better naming for the method is welcome.
Set » removeAny
Implemented as
* » asCollectionDo: aBlock
General purpose implementation of #do:, implemented as
Please note, we assume that strings are to be treated as objects rather than as collection.
* » asCollection
Implemented analog to #asCollectionDo: as
Please note, we assume that strings are to be treated as objects rather than as collection.
Collection » *
Other useful extensions of collection include set operations,
cartesianProduct: aCollectiondifference: aCollectionintersection: aCollectionunion: aCollectionaCollection, same as#difference:
mathematical operations, such as
averageaverage: aBlockdetectHighest: sortBlockdetectLowest: sortBlockdetectMax: aBlockdetectMin: aBlockdeviationmaxValue: aBlockminValue: aBlocknormalizedsumsum: aBlock
and some special enumerations, such as
collectUnion: aBlockcount: aBlockcountNot: aBlockcross: aCollection do: binaryBlock
SequencableCollection » *
For lists, there are more useful enumerations, such as
affect: aBlockcrossDo: binaryBlockpairsDo: binaryBlocktriangleDiagonalDo: binaryBlocktriangleDo: binaryBlockwith: aCollection collect: binaryBlock
as well as other useful extensions, such as:
evenElementsfindFirst: aBlock ifAbsent: exceptionBlockfindLast: aBlock ifAbsent: exceptionBlockindicesOf: anElementoddElementsreverseSort: sortBlockshufflesortReverse: sortBlock, same as above
as well as more literal accessors, such as
secondthird
and smart implementations of #copyFrom:to: that understand negative, as well as, out of range indices
sliceFrom: start to: endsliceFrom: startsliceTo: end
Bag » *
And finally, there are some nice extensions for bags, such as
associationsmaxOccurrencesmostOccurringsortedCounts
SequencableCollection » sliceFrom: start to: end
Answer a copy of the receiver, starting from the element at start index up to and including the element at end index. Other than #copyFrom:to:, this method does never raise a SubscriptOutOfBoundsError. Also, negative indices may be used to count indices from the collection's end rather than start.
The method is implemented as follows
For convenience, we provide #sliceFrom: and #sliceTo: as well.
Filename » *
There are some nice accessors and enumerations for filenames, either recursive or not
allFilesallFilesDo: aBlockfilesfilesDo: aBlock