Skip to content

No insert-by-index operation for OSet #28

Description

@arrowd

The library does not provide a way to insert an element near the given index. I ended up writing it myself via fold:

insertOSet :: WhereTo -> OSet a -> a -> OSet a -> OSet a
insertOSet appendOrPrepend elemsToInsert targetElem set = unbiased $ foldMap' g set
  where
    g e = (Bias :: a -> Bias L a) $
      if e == targetElem
        then if appendOrPrepend == Prepend
          then elemsToInsert |> e
          else e |< elemsToInsert
        else
          singleton e

It'd be nice to have a proper implementation of this function in the library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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