Is there a niffy way to trim values extracted from a form?

28 views
Skip to first unread message

Jacob Emcken

unread,
Feb 6, 2014, 5:27:57 AM2/6/14
to enf...@googlegroups.com
I have extracted input form values, and trimming the entire map afterwards.

I was wondering if there is another (better way)?

I have been looking on wrapping (get-prop :value), but have been unsuccessful so far.


Cheers Jacob
 

Creighton Kirkendall

unread,
Feb 6, 2014, 6:43:33 AM2/6/14
to Enfocus
Jacob,
You could just use fmap to trim the values after read-form.

(let [form-vals (from "#formid" (read-form))
       trim-vals (fmap #(if (string? %) (.trim %) %) form-vals)]
      ...)

CK


--
 
---
You received this message because you are subscribed to the Google Groups "Enfocus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enfocus+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jacob Emcken

unread,
Feb 6, 2014, 7:28:55 AM2/6/14
to enf...@googlegroups.com
That is more or less what I do now.
I just explored the possibility to actually trim the values before they where put in the initial map to avoid traversing it later :)

Thanks for taking the time to answer this non-enfocus question.

Cheers,
Jacob

Creighton Kirkendall

unread,
Feb 6, 2014, 8:56:51 AM2/6/14
to Enfocus
Jacob,
If you want to eliminate that step to reduce code duplication you could wrap the read-form extractor.  

(defn read-form-trimmed []
  (fn [node] 
     (fmap #(if (string? %) (.trim %) %) 
      (from node (read-form)))))
  
;then we can use it as an extractor

(from "#form-id" (read-form-trimmed))

CK
Reply all
Reply to author
Forward
0 new messages