Question: I'm learning Clojure and working on a simple file parsing script. 

I have a file in the form of:

```
pattern1
pattern2
pattern3
pattern1
pattern2
...

```

where each line has a few values (numbers) that I extract. 

If I was to write this in Java for example, I would do something similar to:

```
Map<String, Integer> parse(String line) {
    //using Optional in this toy example, but could be an empty map or something else to
    //signal if first one was actually matched and the values are there
    Optional<Map<String, Integer>> firstMatched = matchFirst(line);
    if (firstMatched.isPresent()) {
        return firstMatched.get();
    }
    //...do the same for 2 remaining patterns
    //...
}

```

Now **what would be a an elegant or idiomatic way** to do something similar **in Clojure**? 

I guess I can use [cond](https://clojuredocs.org/clojure.core/cond), but since there's no binding in the test expression, I'll have to parse the line twice:

```
(defn parse
  [line]
  (cond
    (re-find #"pattern-1-regex" line) (re-find...)
    (re-find #"pattern-2-regex" line) (re-find...

```

I could also use [if-let](https://clojuredocs.org/clojure.core/if-let), but that will be a lot of nesting since there are 3 different options. Imagine with 7 different pattern how that would look like.

Any suggestions? Obviously Java solution is an imperative one and I can do a "return" whenever I want, so what would be the *Clojure/FP way* of dealing with this simple branching.

Answer: 
You do not need to deserialise inner `JSON Object` one more time. It is already deserialised to `Map` instance. So, all you need is casting.

1. Deserialise payload to `Map<String, Object>` which is safe using `com.fasterxml.jackson.core.type.TypeReference` class.
2. Cast inner object to `Map<String, String>` only if `JSON` payload is validated. In other case problem with casting will appear again.
3. To iterate over `Map` do not create `Iterator` object. Use `Java 8` `Stream API` or regular `for` loop.

How code could look like after above changes:

```
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.util.Map;

public class JsonApp {

    public static void main(String[] args) throws IOException {
        File jsonFile = new File("./resource/test.json").getAbsoluteFile();

        ObjectMapper objectMapper = new ObjectMapper();
        // read as Map
        Map<String, Object> busObjMap = objectMapper.readValue(jsonFile, new TypeReference<Map<String, Object>>() {});
        // Inner object is already deserialised as well into Map
        Map<String, String> attributeList = (Map<String, String>) busObjMap.get("attributeList");
        System.out.println("Business Object values:");
        for (Map.Entry<String, Object> entry : busObjMap.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }

        System.out.println("Attribute values:");
        for (Map.Entry<String, String> entry : attributeList.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}

```
Create a class matching your json structure, use that instead , it's better in terms of readability.