Zulip Chat Archive

Stream: Is there code for X?

Topic: HOrElse for lists


Moritz Doll (May 30 2023 at 09:05):

Does this exist somewhere already? Probably way more general, since only the HOrElse class is used

def foo (goal : MVarId) (tacs : List (MVarId  MetaM Unit)) : MetaM Unit :=
  match tacs with
  | [] => pure ()
  | f :: fs => f goal <|> (foo goal fs)

I want to chain together 'finishing' tactics (aka functions MVarId → MetaM Unit), which should be a rather common thing to do.

Eric Wieser (May 30 2023 at 09:26):

docs#list.mfirst is almost that in Lean3. docs4#List.mfirst maybe?

Eric Wieser (May 30 2023 at 09:27):

Are you sure you don't want your base case to be failure?

Moritz Doll (May 30 2023 at 10:02):

ah, yes it should be failure

Moritz Doll (May 30 2023 at 10:15):

the lean4 version of list.mfirst is docs4#List.firstM


Last updated: Dec 20 2023 at 11:08 UTC