text: /** @license ISC License (c) copyright 2017 original and current authors */
  /** @author Ian Hofmann-Hicks (evil) */
  
  var Maybe = require('.')
  var Result = require('../core/types').proxy('Result')
  
  var curry = require('../core/curry')
  var isFunction = require('../core/isFunction')
  var isSameType = require('../core/isSameType')
  
  var applyTransform = function (result) { return result.either(Maybe.Nothing, Maybe.Just); }
  
  // resultToMaybe : Result b a -> Maybe a
  // resultToMaybe : (a -> Result c b) -> a -> Maybe b
  function resultToMaybe(result) {
    if(isFunction(result)) {
      return function(x) {
        var m = result(x)
  
        if(!isSameType(Result, m)) {
          throw new TypeError('resultToMaybe: Result returning function required')
        }
  
        return applyTransform(m)
      }
    }
  
    if(isSameType(Result, result)) {
      return applyTransform(result)
    }
  
    throw new TypeError('resultToMaybe: Result or Result returning function required')
  }
  
  module.exports = curry(resultToMaybe)
  