importOfxTxns
  :: (OfxIn -> Maybe OfxOut)
  -- ^ Examines each OFX transaction.  This function must do something
  -- about duplicates, as 'importOfxTxns' does nothing special to
  -- handle duplicates.
  -> Text
  -- ^ OFX input file
  -> Either OfxToCopperError (Seq (Transaction ()))
importOfxTxns fOfx inp = do
  ofx <- Lens.over Lens._Left (OTCBadOfxFile . pack)
    . OFX.parseTransactions . unpack $ inp
  let ofxMkr t = case mkOfxIn t of
        Nothing -> Accuerr.AccFailure $ NE.singleton t
        Just r -> Accuerr.AccSuccess r
  ofxIns <- case traverse ofxMkr ofx of
    Accuerr.AccFailure fails -> Left (OTCBadOfxAmount fails)
    Accuerr.AccSuccess g -> Right . Seq.fromList $ g
  let maybeOfxOuts = fmap fOfx ofxIns
  return . fmap (uncurry ofxToTxn) . Seq.zip ofxIns . catMaybes
    $ maybeOfxOuts

-- | Given an OFX Transaction, make an OfxIn.  Fails only if the
-- amount cannot be parsed.
importOfxTxns
  :: (OfxIn -> Maybe OfxOut)
  -- ^ Examines each OFX transaction.  This function must do something
  -- about duplicates, as 'importOfxTxns' does nothing special to
  -- handle duplicates.
  -> Text
  -- ^ OFX input file
  -> Either OfxToCopperError (Seq (Transaction ()))
importOfxTxns fOfx inp = do
  ofx <- Lens.over Lens._Left (OTCBadOfxFile . pack)
    . OFX.parseTransactions . unpack $ inp
  let ofxMkr t = case mkOfxIn t of
        Nothing -> Accuerr.AccFailure $ NE.singleton t
        Just r -> Accuerr.AccSuccess r
  ofxIns <- case traverse ofxMkr ofx of
    Accuerr.AccFailure fails -> Left (OTCBadOfxAmount fails)
    Accuerr.AccSuccess g -> Right . Seq.fromList $ g
  let maybeOfxOuts = fmap fOfx ofxIns
  return . fmap (uncurry ofxToTxn) . Seq.zip ofxIns . catMaybes
    $ maybeOfxOuts

-- | Given an OFX Transaction, make an OfxIn.  Fails only if the
-- amount cannot be parsed.
importOfxTxns fOfx inp = do
  ofx <- Lens.over Lens._Left (OTCBadOfxFile . pack)
    . OFX.parseTransactions . unpack $ inp
  let ofxMkr t = case mkOfxIn t of
        Nothing -> Accuerr.AccFailure $ NE.singleton t
        Just r -> Accuerr.AccSuccess r
  ofxIns <- case traverse ofxMkr ofx of
    Accuerr.AccFailure fails -> Left (OTCBadOfxAmount fails)
    Accuerr.AccSuccess g -> Right . Seq.fromList $ g
  let maybeOfxOuts = fmap fOfx ofxIns
  return . fmap (uncurry ofxToTxn) . Seq.zip ofxIns . catMaybes
    $ maybeOfxOuts

-- | Given an OFX Transaction, make an OfxIn.  Fails only if the
-- amount cannot be parsed.