-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Functors-Tests' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Class { | ||
#name : #ApplicativeFunctor, | ||
#superclass : #Functor, | ||
#category : #Functors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Extension { #name : #UndefinedObject } | ||
|
||
{ #category : #'*Functors' } | ||
UndefinedObject >> collect: _ [ | ||
^self | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #Functors } |