@@ -458,26 +458,26 @@ def mapFinIdxM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m]
458
458
map as.size 0 rfl (mkEmpty as.size)
459
459
460
460
@[inline]
461
- def mapIdxM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α) ( f : Nat → α → m β) : m (Array β) :=
461
+ def mapIdxM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : Nat → α → m β) (as : Array α ) : m (Array β) :=
462
462
as.mapFinIdxM fun i a => f i a
463
463
464
464
@[inline]
465
- def findSomeM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α) ( f : α → m (Option β)) : m (Option β) := do
465
+ def findSomeM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α → m (Option β)) (as : Array α ) : m (Option β) := do
466
466
for a in as do
467
467
match (← f a) with
468
468
| some b => return b
469
469
| _ => pure ⟨⟩
470
470
return none
471
471
472
472
@[inline]
473
- def findM? {α : Type } {m : Type → Type } [Monad m] (as : Array α) ( p : α → m Bool) : m (Option α) := do
473
+ def findM? {α : Type } {m : Type → Type } [Monad m] (p : α → m Bool) (as : Array α ) : m (Option α) := do
474
474
for a in as do
475
475
if (← p a) then
476
476
return a
477
477
return none
478
478
479
479
@[inline]
480
- def findIdxM? [Monad m] (as : Array α) ( p : α → m Bool) : m (Option Nat) := do
480
+ def findIdxM? [Monad m] (p : α → m Bool) (as : Array α ) : m (Option Nat) := do
481
481
let mut i := 0
482
482
for a in as do
483
483
if (← p a) then
@@ -529,7 +529,7 @@ def allM {α : Type u} {m : Type → Type w} [Monad m] (p : α → m Bool) (as :
529
529
return !(← as.anyM (start := start) (stop := stop ) fun v => return !(← p v))
530
530
531
531
@[inline]
532
- def findSomeRevM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α) ( f : α → m (Option β)) : m (Option β) :=
532
+ def findSomeRevM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α → m (Option β)) (as : Array α ) : m (Option β) :=
533
533
let rec @[specialize] find : (i : Nat) → i ≤ as.size → m (Option β)
534
534
| 0 , _ => pure none
535
535
| i+1 , h => do
@@ -543,7 +543,7 @@ def findSomeRevM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m]
543
543
find as.size (Nat.le_refl _)
544
544
545
545
@[inline]
546
- def findRevM? {α : Type } {m : Type → Type w} [Monad m] (as : Array α) ( p : α → m Bool) : m (Option α) :=
546
+ def findRevM? {α : Type } {m : Type → Type w} [Monad m] (p : α → m Bool) (as : Array α ) : m (Option α) :=
547
547
as.findSomeRevM? fun a => return if (← p a) then some a else none
548
548
549
549
@[inline]
@@ -572,37 +572,37 @@ def mapFinIdx {α : Type u} {β : Type v} (as : Array α) (f : Fin as.size →
572
572
Id.run <| as.mapFinIdxM f
573
573
574
574
@[inline]
575
- def mapIdx {α : Type u} {β : Type v} (as : Array α) ( f : Nat → α → β) : Array β :=
575
+ def mapIdx {α : Type u} {β : Type v} (f : Nat → α → β) (as : Array α ) : Array β :=
576
576
Id.run <| as.mapIdxM f
577
577
578
578
/-- Turns `#[a, b]` into `#[(a, 0), (b, 1)]`. -/
579
579
def zipWithIndex (arr : Array α) : Array (α × Nat) :=
580
580
arr.mapIdx fun i a => (a, i)
581
581
582
582
@[inline]
583
- def find? {α : Type } (as : Array α ) (p : α → Bool ) : Option α :=
583
+ def find? {α : Type } (p : α → Bool ) (as : Array α ) : Option α :=
584
584
Id.run <| as.findM? p
585
585
586
586
@[inline]
587
- def findSome? {α : Type u} {β : Type v} (as : Array α) ( f : α → Option β) : Option β :=
587
+ def findSome? {α : Type u} {β : Type v} (f : α → Option β) (as : Array α ) : Option β :=
588
588
Id.run <| as.findSomeM? f
589
589
590
590
@[inline]
591
- def findSome! {α : Type u} {β : Type v} [Inhabited β] (a : Array α) ( f : α → Option β) : β :=
592
- match findSome? a f with
591
+ def findSome! {α : Type u} {β : Type v} [Inhabited β] (f : α → Option β) (a : Array α ) : β :=
592
+ match a. findSome? f with
593
593
| some b => b
594
594
| none => panic! "failed to find element"
595
595
596
596
@[inline]
597
- def findSomeRev? {α : Type u} {β : Type v} (as : Array α) ( f : α → Option β) : Option β :=
597
+ def findSomeRev? {α : Type u} {β : Type v} (f : α → Option β) (as : Array α ) : Option β :=
598
598
Id.run <| as.findSomeRevM? f
599
599
600
600
@[inline]
601
- def findRev? {α : Type } (as : Array α ) (p : α → Bool ) : Option α :=
601
+ def findRev? {α : Type } (p : α → Bool ) (as : Array α ) : Option α :=
602
602
Id.run <| as.findRevM? p
603
603
604
604
@[inline]
605
- def findIdx? {α : Type u} (as : Array α ) (p : α → Bool ) : Option Nat :=
605
+ def findIdx? {α : Type u} (p : α → Bool ) (as : Array α ) : Option Nat :=
606
606
let rec @[semireducible] -- This is otherwise irreducible because it uses well-founded recursion.
607
607
loop (j : Nat) :=
608
608
if h : j < as.size then
0 commit comments