Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dissoc
clojure
communitycreator

What is the dissoc maps method in Clojure?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

What is a map in Clojure?

A map is a collection that assigns keys to values.

What is the dissoc map method in Clojure?

The dissoc method is used to remove key-value pairs from a map.

Syntax

(dissoc hmap key)

Parameter

The dissoc method receives the following parameters:

  • hmap: The map we are working with.
  • key: The key used to get the key-value pair that is being removed.

Return value

The dissoc method returns the map without the removed key-value pairs.

Example

(ns clojure.examples.example
(:gen-class))
(defn diss []
(def example (hash-map "z" "98" "x" "90" "u" "53"))
(println (dissoc example "x")))
(diss)
dissoc method example

Explanation

  • Line 3: We define a function diss.
  • Line 4: We define a variable example using the keyword def and we assign our map to it.
  • Line 5: We remove a key-value that has key x from the example map using the method dissoc. We then print the output using the println method.
  • Line 6: We call the diss function.

We can see from the output that the map now has two key-value pairs instead of three.

RELATED TAGS

dissoc
clojure
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring