Skip to content

Seq patterns #3

@hyphenrf

Description

@hyphenrf
let rec takewhile p = function%seq
  | x::xs when p x -> x :: takewhile p xs
  | _ -> []

let rec dropwhile p s = match%seq s with
  | x::xs when p x -> dropwhile p xs
  | xs -> xs

becomes

let rec takewhile p = fun s () -> match s () with
  | Seq.Cons(x, xs) when p x -> Seq.Cons(x, takewhile p xs)
  | _ -> Seq.Nil

How do we deal with pattern nesting, or-patterns, etc..?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions