-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathArray.extension.st
More file actions
48 lines (36 loc) · 1.18 KB
/
Array.extension.st
File metadata and controls
48 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Extension { #name : #Array }
{ #category : #'*DataFrame' }
Array >> calculateDataType [
| types |
types := Set new.
self do: [ :elem | elem ifNotNil: [ types add: elem class ] ].
types ifNotEmpty: [ :classes |
| result |
result := classes inject: classes anyOne into: [ :commonSuperclass :each | self leastCommonSuperclassOf: commonSuperclass and: each ].
"If we cannot detect the type, we configure it as Object."
^ (result withAllSuperclasses includes: String)
ifTrue: [ Object ]
ifFalse: [ result ] ].
^ UndefinedObject
]
{ #category : #'*DataFrame' }
Array >> leastCommonSuperclassOf: firstClass and: secondClass [
"Determines the closest element of class hierarchy which is the common ancestor of two given classes"
| classA classB |
classA := firstClass.
classB := secondClass.
[ classA = Object or: (classB = Object) ]
whileFalse: [
(classA inheritsFromOrEqualTo: classB)
ifTrue: [ ^ classB ].
(classB inheritsFrom: classA)
ifTrue: [ ^ classA ].
classA := classA superclass.
classB := classB superclass. ].
^ Object
]
{ #category : #'*DataFrame' }
Array >> sortIfPossible [
"Sort if possible"
^ [ self sort ] on: Error do: [ self ].
]