Skip to content

Instantly share code, notes, and snippets.

@semmel
Last active August 29, 2023 13:29
Show Gist options
  • Save semmel/935462d74a09b571fbbcd024b54b1921 to your computer and use it in GitHub Desktop.
Save semmel/935462d74a09b571fbbcd024b54b1921 to your computer and use it in GitHub Desktop.
Ramda API for purpose

Operations1 on Collections with Ramda

Purpose List Object Signature(s)
update/insert individual update, assoc*, append, prepend assoc* Idx → a → {k: v} → {k: v}
insert range/collection concat merge* [a] → [a] → [a];{k: v} → {k: v} → {k: v}
retrieve by key/index nth, path, prop prop, path Idx → {a} → a
retrieve many by key/index props
apply fn to single item adjust, modify, modifyPath modify2 3, modifyPath Idx → (v → v) → {k: v} → {k: v}
apply fn to all items map map (a → b) → [a] → [b]; (a → b) → {k: a} → {k: b}
apply each fn to individual evolve evolve3 {k: (v → v)} → {k: v} → {k: v}
apply each fn to each item zipWith(call) [a → b] → [a] → [b]
apply each fn to all items ap [a → b] → [a] → [b]
remove item slice dissoc* String → {k: v} → {k: v}
remove range/collection slice, difference, drop* omit Number → Number → [a] → [a], [a] → [a] → [a], [String] → {k: v} → {k: v}
subset by predicate filter filter (a → boolean) → [a] → [a]; (a → boolean) → {k: a} → {k: a}

Footnotes

  1. Except lenses

  2. modify(p, fn)evolve({[p]: fn})

  3. Missing props are not evaluated. Rather use modify(p, fn)chain(assoc(p), o(fn, R.prop(p))) 2

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