Skip to content

Commit

Permalink
Make IArray indexable too
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Aug 9, 2024
1 parent b082e88 commit b59f716
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/rudiments.Indexable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ import anticipation.*
import symbolism.*

object Indexable:
given [ElementType] => IndexedSeq[ElementType] is Indexable by Int into ElementType =
given [ElementType] => IArray[ElementType] is Indexable by Int into ElementType as iarray =
new Indexable:
type Self = IArray[ElementType]
type Operand = Int
type Result = ElementType

def contains(array: IArray[ElementType], index: Int): Boolean =
index >= 0 && index < array.length

def access(array: IArray[ElementType], index: Int): Result = array(index)

given [ElementType] => IndexedSeq[ElementType] is Indexable by Int into ElementType as indexedSeq =
new Indexable:
type Self = IndexedSeq[ElementType]
type Operand = Int
Expand Down

0 comments on commit b59f716

Please sign in to comment.