Clojure

reducers/mapcat ignores Reduced

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Problem: clojure.core.reducers/mapcat does not stop on reduced? values.

Demonstration:

(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]

Cause: r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.

Patch: lazy-rmapcat2.diff

  1. lazy-rmapcat.diff
    11/Feb/13 8:38 AM
    2 kB
    Christophe Grand
  2. lazy-rmapcat2.diff
    02/Aug/13 2:36 PM
    2 kB
    Stuart Sierra

Activity

Stuart Halloway made changes -
Field Original Value New Value
Fix Version/s Release 1.5 [ 10150 ]
Fix Version/s Release 1.6 [ 10157 ]
Alex Miller made changes -
Approval Vetted [ 10003 ]
Hide
Stuart Sierra added a comment -

Cleaned up description.

Show
Stuart Sierra added a comment - Cleaned up description.
Stuart Sierra made changes -
Description The following code throws an exception:

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.
Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager user/eval184/fn--185 (NO_SOURCE_FILE:6)
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.
Stuart Sierra made changes -
Description Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager user/eval184/fn--185 (NO_SOURCE_FILE:6)
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.
Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.
Hide
Stuart Sierra added a comment -

Original patch lazy-rmapcat.diff had whitespace errors, which I have fixed in a new patch lazy-rmapcat2.diff. I also added the ticket number to the commit message.

Show
Stuart Sierra added a comment - Original patch lazy-rmapcat.diff had whitespace errors, which I have fixed in a new patch lazy-rmapcat2.diff. I also added the ticket number to the commit message.
Stuart Sierra made changes -
Description Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.
Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.

Current patch: {{lazy-rmapcat2.diff}}
Attachment lazy-rmapcat2.diff [ 12089 ]
Hide
Stuart Sierra added a comment -

Screened.

Show
Stuart Sierra added a comment - Screened.
Stuart Sierra made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Alex Miller made changes -
Description Problem: {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

Demonstration:

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]
{code}

This is because r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.

Current patch: {{lazy-rmapcat2.diff}}
*Problem:* {{clojure.core.reducers/mapcat}} does not stop on {{reduced?}} values.

*Demonstration:*

{code}
(require '[clojure.core.reducers :as r])

(->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
             (r/mapcat (juxt inc str))
             (r/take 5)
             (into []))
;; Exception Too eager

;; Expected return value: [1 "0" 2 "1" 3]
{code}

*Cause:* r/mapcat introduces an intermediate reduce which swallows the reduced value coming from r/take.

*Patch:* {{lazy-rmapcat2.diff}}
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: