Skip to content

Lazy Take? #539

@treeowl

Description

@treeowl

The following type family is often useful:

type LazyTake :: Nat -> [k] -> [k]
type family LazyTake n xs where
  LazyTake 0 _ = '[]
  LazyTake n xs = Head xs ': LazyTake (n - 1) (Tail xs)

This is a promoted version of the (partial) function

lazyTake :: Natural -> [a] -> [a]
lazyTake 0 _ = []
lazyTake n xs = head xs : lazyTake (n - 1) (tail xs)

It's useful in constructions like

type LengthAtLeast n xs = xs ~ LazyTake n xs ++ Drop n xs

I imagine this package is not the one such a thing belongs in; any guess where I might find it, or where it might fit?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions