Skip to content

Why is there no first? #39

@Bost

Description

@Bost

I wonder what's the reason behind not having:

(defn first
  "Reducing function that returns the first value."
  ([] nil)
  ([x] x)
  ([x _] x))

? as a "complement" of last.

Edit:
Huh, interestingly enough it won't work at all:

(defn dbg-first
  ([] nil)
  ([x] x)
  ([x y]
   (println ";; x" x "y" y)
   x))

(transduce (comp
            (filter odd?)
            (map inc))
           dbg-first [42]
           [1 2 3 4])
;; x [42] y 2
;; x [42] y 4
;; => [42]

I'm getting convinced this issue can be closed. Happy Xmas! :)

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