Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stab at Smalltalk-25 Collections #289

Draft
wants to merge 2 commits into
base: pure-z3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Functors-Tests/FuntorialityTestTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Class {
#name : #FuntorialityTestTest,
#superclass : #TestCase,
#category : #'Functors-Tests'
}

{ #category : #tests }
FuntorialityTestTest >> checkFunctorialityFor: aClass [
self
assert: ((aClass with: 42) collect: #squared)
equals: (aClass with: 42 squared)
]

{ #category : #tests }
FuntorialityTestTest >> functorsUnderTest [
^{ Array. Bag. Set. OrderedCollection. Just }
]

{ #category : #tests }
FuntorialityTestTest >> testCommutativityEmpty [
self
assert: (nil collect: #moooooo)
equals: nil
]

{ #category : #tests }
FuntorialityTestTest >> testFunctoriality [
self functorsUnderTest do: [ :F | self checkFunctorialityFor: F ]
]

{ #category : #tests }
FuntorialityTestTest >> testIdentityEmpty [
self
assert: (nil collect: #yourself)
equals: nil
]
1 change: 1 addition & 0 deletions src/Functors-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Functors-Tests' }
5 changes: 5 additions & 0 deletions src/Functors/ApplicativeFunctor.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #ApplicativeFunctor,
#superclass : #Functor,
#category : #Functors
}
11 changes: 11 additions & 0 deletions src/Functors/Class.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Extension { #name : #Class }

{ #category : #'*Functors' }
Class >> changeSuperclassTo: newSuperclass [
| oldSuperclass |
oldSuperclass := self superclass.
self basicSuperclass: newSuperclass.
oldSuperclass removeSubclass: self.
newSuperclass addSubclass: self.

]
22 changes: 22 additions & 0 deletions src/Functors/Functor.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class {
#name : #Functor,
#superclass : #Object,
#category : #Functors
}

{ #category : #'class initialization' }
Functor class >> initialize [
Collection changeSuperclassTo: Functor.
]

{ #category : #'Functor API' }
Functor >> collect: aMorphism [
"Lift a morphism a→b to Fa→Fb.
The resulting morphism is expressed set-theoretically aka pointwise:
Assuming self is an element of Fa, and given the a→b,
answer an element of Fb.

Implementors of #collect: must respect identity and composition."

^self subclassResponsibility
]
41 changes: 41 additions & 0 deletions src/Functors/Just.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Class {
#name : #Just,
#superclass : #Maybe,
#instVars : [
'content'
],
#category : #Functors
}

{ #category : #'instance creation' }
Just class >> with: anObject [
^self basicNew
content: anObject;
yourself
]

{ #category : #comparing }
Just >> = rhs [
rhs class = Just ifFalse: [ ^false ].
^content = rhs content
]

{ #category : #'Functor API' }
Just >> collect: aBlock [
^Just with: (aBlock value: content)
]

{ #category : #private }
Just >> content [
^ content
]

{ #category : #private }
Just >> content: anObject [
content := anObject
]

{ #category : #comparing }
Just >> hash [
^content hash
]
10 changes: 10 additions & 0 deletions src/Functors/Maybe.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Class {
#name : #Maybe,
#superclass : #Functor,
#category : #Functors
}

{ #category : #'class initialization' }
Maybe class >> initialize [
UndefinedObject changeSuperclassTo: Maybe
]
6 changes: 6 additions & 0 deletions src/Functors/UndefinedObject.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #UndefinedObject }

{ #category : #'*Functors' }
UndefinedObject >> collect: _ [
^self
]
1 change: 1 addition & 0 deletions src/Functors/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #Functors }
11 changes: 0 additions & 11 deletions src/PreSmalltalks-Tests/HoleTest.class.st

This file was deleted.

19 changes: 0 additions & 19 deletions src/PreSmalltalks/Hole.class.st

This file was deleted.

6 changes: 0 additions & 6 deletions src/PreSmalltalks/ProtoObject.extension.st

This file was deleted.

Loading