-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'flexible_conditionals'
Conflicts: lib/object.fy
- Loading branch information
Showing
27 changed files
with
368 additions
and
135 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
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
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
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
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
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
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
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
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
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
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
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,77 @@ | ||
class FancyEnumerator { | ||
def initialize: @object { | ||
@iterator = 'each: | ||
rewind | ||
} | ||
|
||
def initialize: @object with: @iterator { | ||
rewind | ||
} | ||
|
||
def next { | ||
if: @peeked then: { | ||
@peeked = false | ||
@peek | ||
} else: { | ||
result = @fiber resume | ||
if: (@fiber alive?) then: { | ||
return result | ||
} else: { | ||
(Fancy StopIteration new: result) raise! | ||
} | ||
} | ||
} | ||
|
||
def peek { | ||
""" | ||
Returns the next object in the FancyEnumerator, but doesn't move the | ||
internal position forward. | ||
When the position reaches the end, a Fancy StopIteration exception is | ||
raised. | ||
a = [1,2,3] | ||
e = a to_enum | ||
e next p #=> 1 | ||
e peek p #=> 2 | ||
e peek p #=> 2 | ||
e peek p #=> 2 | ||
e next p #=> 2 | ||
e next p #=> 3 | ||
e next p #=> raises Fancy StopIteration | ||
""" | ||
|
||
unless: @peeked do: { | ||
@peeked = true | ||
@peek = @fiber resume | ||
if: (@fiber alive?) then: { | ||
return @peek | ||
} else: { | ||
(Fancy StopIteration new: result) raise! | ||
} | ||
} | ||
|
||
return @peek | ||
} | ||
|
||
def rewind { | ||
@peeked = false | ||
@peek = nil | ||
|
||
@fiber = Fiber new: { | ||
param = |element| { yield: element } | ||
@object send_message: @iterator with_params: [param] | ||
} | ||
} | ||
|
||
def with: object each: block { | ||
loop: { | ||
try { | ||
block call: [next, object] | ||
} catch (Fancy StopIteration) => ex { | ||
return object | ||
} | ||
} | ||
|
||
return object | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.