def fmask(bandname="fmask"):
    """ Function to use in Collections that have a quality band computed with
    fmask algorithm

    The use of this function is a little different from the other because it
    is a function that returns a function, so you must call it to return the
    function to use in map:

    `masked = collection.map(cloud_mask.fmask())`

    :param bandname: name of the band that holds the fmask information
    :type bandname: str
    :return: a function to use in map
    :rtype: function
    """

    def fmask(image):
        imgFmask = image.select(bandname)
        shadow = imgFmask.eq(3)
        snow = imgFmask.eq(4)
        cloud = imgFmask.eq(5)

        mask = shadow.Or(snow).Or(cloud)

        imgMask = image.updateMask(mask.Not())
        return imgMask
    return fmask