Skip to content
nobeans edited this page Sep 13, 2010 · 9 revisions

since v0.1

This is useful for debugging of method chains. You can confirm the value on the way of method chains.

As category:


        import org.jggug.kobo.commons.lang.ObjectCategory
        use (ObjectCategory) {
            assert "string" == "String".toUpperCase().tap {
                assert it == "STRING"
            }.toLowerCase()
        }  

As enhanced Object:


        import org.jggug.kobo.commons.lang.ObjectUtils
        ObjectUtils.extendMetaClass()
        assert [12, 99] == (1..12).grep { it % 2 == 0 }.tap {
            assert it == [2, 4, 6, 8, 10, 12]
        }.grep {it % 3 == 0}.tap {
            assert it == [6, 12]
        }.grep {it == 12}.tap {
            assert it == [12]
        }.tap {
            it << 99  // it's possible to modify an object in a closure of tap
        }

As utility:


        import org.jggug.kobo.commons.lang.ObjectUtils
        assert "string" == ObjectUtils.tap("String".toUpperCase(), {
            assert it == "STRING"
        }).toLowerCase()
Clone this wiki locally