Skip to content

Commit

Permalink
Regex-inspired optics (#3498)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored Oct 10, 2024
1 parent c713cd3 commit 8288fd4
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
18 changes: 18 additions & 0 deletions arrow-libs/optics/arrow-optics/api/arrow-optics.api
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public final class arrow/optics/PIso$DefaultImpls {
public static fun compose (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional;
public static fun compose (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism;
public static fun compose (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun composeLazy (Larrow/optics/PIso;Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun exists (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun findOrNull (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static fun first (Larrow/optics/PIso;)Larrow/optics/PIso;
Expand Down Expand Up @@ -201,6 +202,7 @@ public final class arrow/optics/PLens$DefaultImpls {
public static fun compose (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens;
public static fun compose (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional;
public static fun compose (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun composeLazy (Larrow/optics/PLens;Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun exists (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun findOrNull (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static fun first (Larrow/optics/PLens;)Larrow/optics/PLens;
Expand Down Expand Up @@ -263,6 +265,7 @@ public final class arrow/optics/POptional$DefaultImpls {
public static fun choice (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun compose (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional;
public static fun compose (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun composeLazy (Larrow/optics/POptional;Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun exists (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun findOrNull (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static fun first (Larrow/optics/POptional;)Larrow/optics/POptional;
Expand Down Expand Up @@ -331,6 +334,7 @@ public final class arrow/optics/PPrism$DefaultImpls {
public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional;
public static fun compose (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism;
public static fun compose (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun composeLazy (Larrow/optics/PPrism;Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun exists (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun findOrNull (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static fun first (Larrow/optics/PPrism;)Larrow/optics/PPrism;
Expand Down Expand Up @@ -363,6 +367,7 @@ public abstract interface class arrow/optics/PTraversal {
public abstract fun any (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public abstract fun choice (Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public abstract fun compose (Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public abstract fun composeLazy (Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun either ()Larrow/optics/PTraversal;
public abstract fun exists (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public abstract fun findOrNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
Expand Down Expand Up @@ -445,6 +450,7 @@ public final class arrow/optics/PTraversal$DefaultImpls {
public static fun any (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static fun composeLazy (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function0;)Larrow/optics/PTraversal;
public static fun exists (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z
public static fun findOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static fun firstOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object;
Expand Down Expand Up @@ -570,6 +576,18 @@ public abstract interface class arrow/optics/match/MatchScope {
public abstract fun then (Larrow/optics/POptional;Lkotlin/jvm/functions/Function1;)V
}

public final class arrow/optics/regex/RegexKt {
public static final fun and (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static final fun onceOrMore (Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static final fun times (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static final fun zeroOrMore (Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
}

public final class arrow/optics/regex/dsl/RegexKt {
public static final fun onceOrMore (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
public static final fun zeroOrMore (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal;
}

public abstract interface class arrow/optics/typeclasses/At {
public static final field Companion Larrow/optics/typeclasses/At$Companion;
public abstract fun at (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens;
Expand Down
7 changes: 7 additions & 0 deletions arrow-libs/optics/arrow-optics/api/arrow-optics.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ abstract interface <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotli
abstract fun modify(#A, kotlin/Function1<#C, #D>): #B // arrow.optics/PTraversal.modify|modify(1:0;kotlin.Function1<1:2,1:3>){}[0]
open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> choice(arrow.optics/PTraversal<#A1, #B1, #C, #D>): arrow.optics/PTraversal<arrow.core/Either<#A, #A1>, arrow.core/Either<#B, #B1>, #C, #D> // arrow.optics/PTraversal.choice|choice(arrow.optics.PTraversal<0:0,0:1,1:2,1:3>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> compose(arrow.optics/PTraversal<in #C, out #D, out #A1, in #B1>): arrow.optics/PTraversal<#A, #B, #A1, #B1> // arrow.optics/PTraversal.compose|compose(arrow.optics.PTraversal<in|1:2,out|1:3,out|0:0,in|0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> composeLazy(kotlin/Function0<arrow.optics/PTraversal<in #C, out #D, out #A1, in #B1>>): arrow.optics/PTraversal<#A, #B, #A1, #B1> // arrow.optics/PTraversal.composeLazy|composeLazy(kotlin.Function0<arrow.optics.PTraversal<in|1:2,out|1:3,out|0:0,in|0:1>>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> plus(arrow.optics/PTraversal<in #C, out #D, out #A1, in #B1>): arrow.optics/PTraversal<#A, #B, #A1, #B1> // arrow.optics/PTraversal.plus|plus(arrow.optics.PTraversal<in|1:2,out|1:3,out|0:0,in|0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
open fun all(#A, kotlin/Function1<#C, kotlin/Boolean>): kotlin/Boolean // arrow.optics/PTraversal.all|all(1:0;kotlin.Function1<1:2,kotlin.Boolean>){}[0]
open fun any(#A, kotlin/Function1<#C, kotlin/Boolean>): kotlin/Boolean // arrow.optics/PTraversal.any|any(1:0;kotlin.Function1<1:2,kotlin.Boolean>){}[0]
Expand Down Expand Up @@ -359,6 +360,8 @@ final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/POpt
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/POptional<#A, #A, kotlin.collections/Map<#B, #C>, kotlin.collections/Map<#B, #C>>).arrow.optics.dsl/index(#B): arrow.optics/POptional<#A, #A, #C, #C> // arrow.optics.dsl/index|[email protected]<0:0,0:0,kotlin.collections.Map<0:1,0:2>,kotlin.collections.Map<0:1,0:2>>(0:1){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal.Companion).arrow.optics/fromLenses(arrow.optics/PLens<#A, #A, #B, #C>, kotlin/Array<out arrow.optics/PLens<#A, #A, #B, #C>>...): arrow.optics/PTraversal<#A, #A, #B, #C> // arrow.optics/fromLenses|[email protected](arrow.optics.PLens<0:0,0:0,0:1,0:2>;kotlin.Array<out|arrow.optics.PLens<0:0,0:0,0:1,0:2>>...){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #B>).arrow.optics.dsl/every(arrow.optics/PTraversal<#B, #B, #C, #C>): arrow.optics/PTraversal<#A, #A, #C, #C> // arrow.optics.dsl/every|[email protected]<0:0,0:0,0:1,0:1>(arrow.optics.PTraversal<0:1,0:1,0:2,0:2>){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #C>).arrow.optics.regex/and(arrow.optics/PTraversal<#A, #A, #B, #C>): arrow.optics/PTraversal<#A, #A, #B, #C> // arrow.optics.regex/and|[email protected]<0:0,0:0,0:1,0:2>(arrow.optics.PTraversal<0:0,0:0,0:1,0:2>){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #C>).arrow.optics.regex/times(arrow.optics/PTraversal<#A, #A, #B, #C>): arrow.optics/PTraversal<#A, #A, #B, #C> // arrow.optics.regex/times|[email protected]<0:0,0:0,0:1,0:2>(arrow.optics.PTraversal<0:0,0:0,0:1,0:2>){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, kotlin.collections/Map<#B, #C>, kotlin.collections/Map<#B, #C>>).arrow.optics.dsl/at(#B): arrow.optics/PTraversal<#A, #A, arrow.core/Option<#C>, arrow.core/Option<#C>> // arrow.optics.dsl/at|[email protected]<0:0,0:0,kotlin.collections.Map<0:1,0:2>,kotlin.collections.Map<0:1,0:2>>(0:1){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, kotlin.collections/Map<#B, #C>, kotlin.collections/Map<#B, #C>>).arrow.optics.dsl/filterIndex(kotlin/Function1<#B, kotlin/Boolean>): arrow.optics/PTraversal<#A, #A, #C, #C> // arrow.optics.dsl/filterIndex|[email protected]<0:0,0:0,kotlin.collections.Map<0:1,0:2>,kotlin.collections.Map<0:1,0:2>>(kotlin.Function1<0:1,kotlin.Boolean>){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, kotlin.collections/Map<#B, #C>, kotlin.collections/Map<#B, #C>>).arrow.optics.dsl/index(#B): arrow.optics/PTraversal<#A, #A, #C, #C> // arrow.optics.dsl/index|[email protected]<0:0,0:0,kotlin.collections.Map<0:1,0:2>,kotlin.collections.Map<0:1,0:2>>(0:1){0§<kotlin.Any?>;1§<kotlin.Any?>;2§<kotlin.Any?>}[0]
Expand All @@ -376,6 +379,8 @@ final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/POptional<#A, #A, kot
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/POptional<#A, #A, kotlin.collections/Set<#B>, kotlin.collections/Set<#B>>).arrow.optics.dsl/at(#B): arrow.optics/POptional<#A, #A, kotlin/Boolean, kotlin/Boolean> // arrow.optics.dsl/at|[email protected]<0:0,0:0,kotlin.collections.Set<0:1>,kotlin.collections.Set<0:1>>(0:1){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/POptional<#A, #A, kotlin.sequences/Sequence<#B>, kotlin.sequences/Sequence<#B>>).arrow.optics.dsl/index(kotlin/Int): arrow.optics/POptional<#A, #A, #B, #B> // arrow.optics.dsl/index|[email protected]<0:0,0:0,kotlin.sequences.Sequence<0:1>,kotlin.sequences.Sequence<0:1>>(kotlin.Int){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #B>).arrow.optics.dsl/filter(kotlin/Function1<#B, kotlin/Boolean>): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.dsl/filter|[email protected]<0:0,0:0,0:1,0:1>(kotlin.Function1<0:1,kotlin.Boolean>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #B>).arrow.optics.regex.dsl/onceOrMore(arrow.optics/PTraversal<#B, #B, #B, #B>): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.regex.dsl/onceOrMore|[email protected]<0:0,0:0,0:1,0:1>(arrow.optics.PTraversal<0:1,0:1,0:1,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, #B, #B>).arrow.optics.regex.dsl/zeroOrMore(arrow.optics/PTraversal<#B, #B, #B, #B>): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.regex.dsl/zeroOrMore|[email protected]<0:0,0:0,0:1,0:1>(arrow.optics.PTraversal<0:1,0:1,0:1,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, arrow.core/NonEmptyList<#B>, arrow.core/NonEmptyList<#B>>).arrow.optics.dsl/filterIndex(kotlin/Function1<kotlin/Int, kotlin/Boolean>): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.dsl/filterIndex|[email protected]<0:0,0:0,arrow.core.NonEmptyList<0:1>,arrow.core.NonEmptyList<0:1>>(kotlin.Function1<kotlin.Int,kotlin.Boolean>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, arrow.core/NonEmptyList<#B>, arrow.core/NonEmptyList<#B>>).arrow.optics.dsl/index(kotlin/Int): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.dsl/index|[email protected]<0:0,0:0,arrow.core.NonEmptyList<0:1>,arrow.core.NonEmptyList<0:1>>(kotlin.Int){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.optics/PTraversal<#A, #A, kotlin.collections/List<#B>, kotlin.collections/List<#B>>).arrow.optics.dsl/filterIndex(kotlin/Function1<kotlin/Int, kotlin/Boolean>): arrow.optics/PTraversal<#A, #A, #B, #B> // arrow.optics.dsl/filterIndex|[email protected]<0:0,0:0,kotlin.collections.List<0:1>,kotlin.collections.List<0:1>>(kotlin.Function1<kotlin.Int,kotlin.Boolean>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
Expand All @@ -398,5 +403,7 @@ final fun <#A: kotlin/Any?> (kotlin.collections/List<#A>).arrow.optics/uncons():
final fun <#A: kotlin/Any?> (kotlin.collections/List<#A>).arrow.optics/unsnoc(): kotlin/Pair<kotlin.collections/List<#A>, #A>? // arrow.optics/unsnoc|[email protected]<0:0>(){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> arrow.optics.match/equalsTo(#A): arrow.optics/POptional<#A, #A, #A, #A> // arrow.optics.match/equalsTo|equalsTo(0:0){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> arrow.optics.match/predicate(kotlin/Function1<#A, kotlin/Boolean>): arrow.optics/POptional<#A, #A, #A, #A> // arrow.optics.match/predicate|predicate(kotlin.Function1<0:0,kotlin.Boolean>){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> arrow.optics.regex/onceOrMore(arrow.optics/PTraversal<#A, #A, #A, #A>): arrow.optics/PTraversal<#A, #A, #A, #A> // arrow.optics.regex/onceOrMore|onceOrMore(arrow.optics.PTraversal<0:0,0:0,0:0,0:0>){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> arrow.optics.regex/zeroOrMore(arrow.optics/PTraversal<#A, #A, #A, #A>): arrow.optics/PTraversal<#A, #A, #A, #A> // arrow.optics.regex/zeroOrMore|zeroOrMore(arrow.optics.PTraversal<0:0,0:0,0:0,0:0>){0§<kotlin.Any?>}[0]
final inline fun <#A: kotlin/Any, #B: reified #A> arrow.optics.match/instanceOf(): arrow.optics/POptional<#A, #A, #B, #B> // arrow.optics.match/instanceOf|instanceOf(){0§<kotlin.Any>;1§<0:0>}[0]
final inline fun <#A: kotlin/Any?, #B: kotlin/Any, #C: reified #B> (arrow.optics/POptional<#A, #A, #B, #B>).arrow.optics.match/ifInstanceOf(): arrow.optics/POptional<#A, #A, #C, #C> // arrow.optics.match/ifInstanceOf|[email protected]<0:0,0:0,0:1,0:1>(){0§<kotlin.Any?>;1§<kotlin.Any>;2§<0:1>}[0]
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public interface PTraversal<S, T, A, B> {
this@PTraversal.modify(source) { b -> other.modify(b, map) }
}

public infix fun <C, D> composeLazy(other: () -> PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D> =
object : PTraversal<S, T, C, D> {
override fun <R> foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: C) -> R): R =
this@PTraversal.foldMap(initial, combine, source) { c -> other().foldMap(initial, combine, c, map) }

override fun modify(source: S, map: (focus: C) -> D): T =
this@PTraversal.modify(source) { b -> other().modify(b, map) }
}

public operator fun <C, D> plus(other: PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D> =
this compose other

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package arrow.optics.regex

import arrow.optics.Iso
import arrow.optics.Traversal
import arrow.optics.PTraversal

/**
* [Traversal] that aggregates the elements of two other traversals.
*
* For example, this may aggregate the values coming from several fields of the same type.
*/
public infix fun <T, A, B> PTraversal<T, T, A, B>.and(other: PTraversal<T, T, A, B>): PTraversal<T, T, A, B> =
object : PTraversal<T, T, A, B> {
override fun <R> foldMap(initial: R, combine: (R, R) -> R, source: T, map: (focus: A) -> R): R {
val meFolded = this@and.foldMap(initial, combine, source, map)
val otherFolded = other.foldMap(initial, combine, source, map)
return combine(meFolded, otherFolded)
}

override fun modify(source: T, map: (focus: A) -> B): T =
other.modify(this@and.modify(source, map), map)
}

/**
* [Traversal] that aggregates the elements of two other traversals.
*
* For example, this may aggregate the values coming from several fields of the same type.
*/
public operator fun <T, A, B> PTraversal<T, T, A, B>.times(other: PTraversal<T, T, A, B>): PTraversal<T, T, A, B> =
this and other

/**
* Aggregates the elements by "going into" the desired traversal repeatedly.
* This traversal is especially useful to inspect values which contain fields of
* the same type within them.
*
* **Important**: [onceOrMore] may operate over the same value more than once,
* if there is more than one path arriving to it.
*/
public fun <A> onceOrMore(traversal: Traversal<A, A>): Traversal<A, A> =
traversal composeLazy { zeroOrMore(traversal) }

/**
* Aggregates the elements by "going into" the desired traversal repeatedly,
* including the starting value itself.
* This traversal is especially useful to inspect values which contain fields of
* the same type within them.
*
* **Important**: [zeroOrMore] may operate over the same value more than once,
* if there is more than one path arriving to it.
*/
public fun <A> zeroOrMore(traversal: Traversal<A, A>): Traversal<A, A> =
Iso.id<A>() and onceOrMore(traversal)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package arrow.optics.regex.dsl

import arrow.optics.regex.onceOrMore as regexOnceOrMore
import arrow.optics.regex.zeroOrMore as regexZeroOrMore
import arrow.optics.Traversal

public fun <S, A> Traversal<S, A>.onceOrMore(traversal: Traversal<A, A>): Traversal<S, A> =
this compose regexOnceOrMore(traversal)

public fun <S, A> Traversal<S, A>.zeroOrMore(traversal: Traversal<A, A>): Traversal<S, A> =
this compose regexZeroOrMore(traversal)
Loading

0 comments on commit 8288fd4

Please sign in to comment.