Skip to content

Commit

Permalink
implementation classes for Cursor in it.unibo.tuprolog.utils.impl
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed May 5, 2020
1 parent f56eb1b commit 7a4ddbc
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/utils/Cursor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package it.unibo.tuprolog.utils

import it.unibo.tuprolog.utils.impl.ConjunctionCursor
import it.unibo.tuprolog.utils.impl.EmptyCursor
import it.unibo.tuprolog.utils.impl.MapperCursor
import kotlin.js.JsName
import kotlin.jvm.JvmStatic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

package it.unibo.tuprolog.utils

import it.unibo.tuprolog.utils.impl.ConjunctionCursor
import it.unibo.tuprolog.utils.impl.EmptyCursor
import it.unibo.tuprolog.utils.impl.LazyCursor
import kotlin.jvm.JvmName


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor

internal abstract class AbstractCursor<T> : Cursor<T> {
override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor

internal data class ConjunctionCursor<T>(val first: Cursor<out T>, val second: Cursor<out T>) : AbstractCursor<T>() {
override val isOver: Boolean
get() = first.isOver && second.isOver

override val next: Cursor<out T>
get() = if (first.hasNext) ConjunctionCursor(first.next, second) else second
get() = if (first.hasNext) ConjunctionCursor(
first.next,
second
) else second

override val current: T?
get() = if (first.hasNext) first.current else second.current
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor

internal object EmptyCursor : AbstractCursor<Nothing>() {
override val next: Cursor<Nothing>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor

internal data class LazyCursor<T>(val iterator: Iterator<T>) : AbstractCursor<T>() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor

internal data class MapperCursor<T, R>(val wrapped: Cursor<out T>, val mapper: (T) -> R) : AbstractCursor<R>() {
override val next: Cursor<out R> by lazy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package it.unibo.tuprolog.utils
package it.unibo.tuprolog.utils.impl

import it.unibo.tuprolog.utils.Cursor
import it.unibo.tuprolog.utils.toCursor

internal data class NonLastCursor<T>(val iterator: Iterator<T>) : AbstractCursor<T>() {

Expand Down

0 comments on commit 7a4ddbc

Please sign in to comment.