<commit_before>spec = (require 'hifive')!
{id, ok, eq} = require '../../utils'
Maybe = require '../../../src/monads/maybe'

module.exports = spec 'Maybe a' (_, spec) ->

  spec '{} Maybe' (o) ->
     Just = (v) -> Maybe.Just v

     o '.of(x) should return a monad with x as value.' ->
       (Just 1 .chain id) `eq` 1

     o '.map(f) should return a monad transformed by f.' ->
       (Just 1 .map (+ 1) .chain id) `eq` 2

     o '.chain(f) should apply f to the value.' ->
       (Just 1 .chain id) `eq` 1

     o '.ap(b) should apply value to b’s value.' ->
       (Just id .ap (Just 1) .chain id) `eq` 1

     o '.orElse(f) should ignore the operation.' ->
       (Just 1 .or-else (-> 2) .chain id) `eq` 1

  spec '{} Nothing' (o) ->
     Nothing = Maybe.Nothing!
     o '.of(x), .map(f), .chain(f) should return Nothing.' ->
       (Nothing.of 1) `eq` Nothing
       (Nothing.map (-> 1)) `eq` Nothing
       (Nothing.chain (-> 1)) `eq` Nothing

     o '.ap(b) should return b.' ->
       b = Maybe.of 1
       (Nothing.ap b) `eq` b

     o '.orElse(f) should apply f.' ->
       (Nothing.or-else -> 1) `eq` 1<commit_msg>Correct structure for the tests.<commit_after>spec = (require 'hifive')!
{id, ok, eq} = require '../../utils'
Maybe = require '../../../src/monads/maybe'

module.exports = spec 'Maybe a' (_, spec) ->

  spec 'Just a' (o) ->
     Just = (v) -> Maybe.Just v

     o '.of(x) should return a monad with x as value.' ->
       (Just 1 .chain id) `eq` 1

     o '.map(f) should return a monad transformed by f.' ->
       (Just 1 .map (+ 1) .chain id) `eq` 2

     o '.chain(f) should apply f to the value.' ->
       (Just 1 .chain id) `eq` 1

     o '.ap(b) should apply value to b’s value.' ->
       (Just id .ap (Just 1) .chain id) `eq` 1

     o '.orElse(f) should ignore the operation.' ->
       (Just 1 .or-else (-> 2) .chain id) `eq` 1

  spec 'Nothing' (o) ->
     Nothing = Maybe.Nothing!
     o '.of(x), .map(f), .chain(f) should return Nothing.' ->
       (Nothing.of 1) `eq` Nothing
       (Nothing.map (-> 1)) `eq` Nothing
       (Nothing.chain (-> 1)) `eq` Nothing

     o '.ap(b) should return b.' ->
       b = Maybe.of 1
       (Nothing.ap b) `eq` b

     o '.orElse(f) should apply f.' ->
       (Nothing.or-else -> 1) `eq` 1
{'fraction_non_alphanumeric': 0.19196822594880847, 'fraction_numerical': 0.01588702559576346, 'mean_word_length': 1.940337224383917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5688401', 'n_tokens_mistral': 857, 'n_tokens_neox': 801, 'n_words': 296}