Skip to content

Commit

Permalink
Refactor: Remove Seq (since it sucked)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBizzle committed Feb 5, 2017
1 parent c658df3 commit eb361a6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 89 deletions.
54 changes: 41 additions & 13 deletions jvm/src/main/coffee/engine/core/abstractagentset.coffee
Expand Up @@ -3,35 +3,34 @@
Nobody = require('./nobody')
projectionSort = require('./projectionsort')
NLType = require('./typechecker')
Seq = require('util/seq')
Iterator = require('util/iterator')
Shufflerator = require('util/shufflerator')
stableSort = require('util/stablesort')

{ foldl, map } = require('brazierjs/array')
{ pipeline } = require('brazierjs/function')
{ keys } = require('brazierjs/object')
{ all, contains, exists, filter, foldl, forEach, map } = require('brazierjs/array')
{ pipeline } = require('brazierjs/function')
{ keys } = require('brazierjs/object')

{ DeathInterrupt: Death } = require('util/exception')

# Never instantiate this class directly --JAB (5/7/14)
module.exports =
class AbstractAgentSet extends Seq
class AbstractAgentSet

@_nextInt: undefined # (Number) => Number
@_selfManager: undefined # SelfManager
@_world: undefined # World

# (Array[T], String, String) => AbstractAgentSet
constructor: (agents, @_agentTypeName, @_specialName) ->
super(agents)
constructor: (@_agentArr, @_agentTypeName, @_specialName) ->

# (() => Boolean) => AbstractAgentSet[T]
agentFilter: (f) ->
@filter(@_lazyGetSelfManager().askAgent(f))

# (() => Boolean) => Boolean
agentAll: (f) ->
@every(@_lazyGetSelfManager().askAgent(f))
all(@_lazyGetSelfManager().askAgent(f))(@toArray())

# (() => Any, Boolean) => Unit
ask: (f, shouldShuffle) ->
Expand All @@ -57,14 +56,39 @@ module.exports =
getPatchAt = (x, y) => @_lazyGetWorld().getPatchAt(x, y)
require('./agentset/atpoints')(getSelf, getPatchAt).call(this, points)

# (T) => Boolean
contains: (item) ->
contains(item)(@toArray())

# (Array[T]) => AbstractAgentSet[T]
copyWithNewAgents: (agents) ->
@_generateFrom(agents)

# ((T) => Boolean) => Boolean
exists: (pred) ->
exists(pred)(@toArray())

# ((T) => Boolean) => Seq[T]
filter: (pred) ->
@_generateFrom(filter(pred)(@toArray()))

# ((T) => Unit) => Unit
forEach: (f) ->
forEach(f)(@toArray())
return

# () => String
getSpecialName: ->
@_specialName

# () => Boolean
isEmpty: ->
@size() is 0

# () => Iterator
iterator: ->
new Iterator(@_agentArr)

# (() => Number) => AbstractAgentSet[T]
maxesBy: (f) ->
@copyWithNewAgents(@_findMaxesBy(f))
Expand Down Expand Up @@ -115,6 +139,10 @@ module.exports =
shufflerator: ->
new Shufflerator(@toArray(), ((agent) -> agent?.id >= 0), @_lazyGetNextIntFunc())

# () => Number
size: ->
@toArray().length

# () => Array[T]
sort: ->
if @isEmpty()
Expand All @@ -128,8 +156,8 @@ module.exports =

# () => Array[T]
toArray: ->
@_items = @iterator().toArray() # Prune out dead agents --JAB (7/21/14)
@_items[..]
@_agentArr = @iterator().toArray() # Prune out dead agents --JAB (7/21/14)
@_agentArr[..]

# () => String
toString: ->
Expand Down Expand Up @@ -199,7 +227,7 @@ module.exports =
else
[currentBest, currentWinners]

[[], winners] = @foldl(foldFunc, [worstPossible, []])
[[], winners] = foldl(foldFunc)([worstPossible, []])(@toArray())
winners

# [U] @ (() => U) => Array[T]
Expand Down Expand Up @@ -240,8 +268,8 @@ module.exports =
_lazyGetWorld: ->
if @_world?
@_world
else if @_items[0]?
@_world = @_items[0].world
else if @_agentArr[0]?
@_world = @_agentArr[0].world
@_world
else
undefined
75 changes: 0 additions & 75 deletions jvm/src/main/coffee/util/seq.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion tortoise/src/main/scala/Prims.scala
Expand Up @@ -94,7 +94,7 @@ trait ReporterPrims extends PrimUtils {
case _: prim._unaryminus => s" -${arg(0)}" // The space is important, because these can be nested --JAB (6/12/14)
case _: prim._not => s"!${arg(0)}"
case _: prim._count => s"${arg(0)}.size()"
case _: prim._any => s"${arg(0)}.nonEmpty()"
case _: prim._any => s"!${arg(0)}.isEmpty()"
case _: prim._word => ("''" +: args).map(arg => s"Dump($arg)").mkString("(", " + ", ")")
case _: prim._of => generateOf(r)
case _: prim.etc._ifelsevalue => s"(${arg(0)} ? ${arg(1)} : ${arg(2)})"
Expand Down

0 comments on commit eb361a6

Please sign in to comment.