What would be good/idiomatic way of naming functions that either fail or return nothing?

Would adding a spec to your problem solve your need?

Failjure is based on monadic error handling, which comes from Haskell. In Haskell, type signatures are used for this. And when reading Haskell code, I allways get this information from the type signatures. Elm is another example.

Edit: here’s a way to do it, there might be better ways. I also realized that I might want to prefix failing functions with try-, so that’s what you were really asking for!

(ns scratch.fail
  (:require [failjure.core :as f]
            [clojure.spec.alpha :as s]
            [failjure.spec]))

(defn try-parse-int [s]
  (f/try* (Integer/parseInt s)))

(s/fdef try-parse-int
  :args (s/cat :s string?)
  :ret (s/or :fail :failjure.spec/failure
             :success int?))
2 Likes