Romans 8:26-28 says:
“Likewise the Spirit also helpeth our infirmities: for we know not what we should pray for as we ought: but the Spirit itself maketh intercession for us with groanings which cannot be uttered. And he that searcheth the hearts knoweth what is the mind of the Spirit, because he maketh intercession for the saints according to the will of God. And we know that all things work together for good to them that love God, to them who are the called according to his purpose.”
Joseph Smith said:
“Trials will only give us the knowledge necessary to understand the minds of the ancients. For my part, I think I never could have felt as I now do, if I had not suffered the wrongs that I have suffered. All things shall work together for good to them that love God” (Teachings of Presidents of the Church: Joseph Smith, p. 230-231).